DIVGOLD why WA?

This is my submission link (CodeChef: Practical coding for everyone)

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 :slight_smile:

#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;
}
}
}

Check for : OHH

Answer should be HHO :slight_smile:

1 Like

for ADDLEE the answer should be ADDEEL but your code gives ADDELE

okay I got my error. thank you

1 Like