Codechef Starters 30 Division 4 (Rated) Поваление шеф -поваров Уэй

#include<iostream>
#include<vector>
#include<algorithm>
#include<climits>
#include<string>
using namespace std;

class solution
{
public:
	void solve()
	{
		int n;
		cin >> n;
		string s1, s2;
		cin >> s1;
		s2 = s1;
		sort(s1.begin(), s1.end());
		for (int i = 1; i <= n; i++)
		{
			if(s2[i]!=s1[i])
				swap(s2[i], s2[n-1-i]);
		}

		if (s1==s2)
			cout << "YES\n";
		else
			cout << "NO\n";
	}
};
int main()
{
	solution ss;

	int t;
	cin >> t;
	while (t--)
    {
		ss.solve();
	}

	return 0;
}
coder