This is my submission link (http://www.codechef.com/viewsolution/6566159)
This is my code and I dont know why I am getting WA, can someone point out from which kind of testcase will my code get WA. Thanks
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
int T;
cin >> T;
while(T--)
{
string str;
string str1;
int length;
cin >> length >> str;
str1 = str;
int index = 0;
int index1 = 0;
string a;
int c = 0;
sort(str1.begin(),str1.end());
for(int x = 0; x < length; x++)
{
if(str1[x] != str[x])
{
a = a + str1[x];
index = x;
c++;
break;
}
}
if(c != 0)
{
for(int x = length-1; x >= 0; x--)
{
if(str[x] == a[0])
{
index1 = x;
break;
}
}
str.insert(index,a);
str.erase(index1+1,1);
for(int x = 0; x < length; x++)
cout << str[x];
cout << endl;
}
else
{
for(int x = 0; x < length; x++)
cout << str[x];
cout << endl;
}
}
}