Can anyone please help me why my code is failing for large test cases?


#1

string helper(string &a,int B,int index)
{
if(B==0 || index==a.length()-1)
{
return a;
}
int i,s=INT_MIN,x;
for(i=index;i<a.length();i++)
{
if(a[i]>s)
{
x=i;
s=a[i];
}
}
if(x==index)
{
index++;
return helper(a,B,index);
}
else
{
swap(a[index],a[x]);
index++;
return helper(a,B-1,index);
}
}
string Solution::solve(string A, int B)
{
if(A.length()<=1)
{
return A;
}
return helper(A,B,0);
}