Similar to permutation of a string


#1

void fun(string &A,int k,int ind,string &ans)
{
if(k<0)
return;
if(k>=0)
{
if(ans<A)
ans=A;

}
if(k==0)
return;
for(int i=ind;i<A.length();i++)
{
    
    swap(A[ind],A[i]);
    if(ind==i)
    fun(A,k,ind+1,ans);
    else
    fun(A,k-1,ind+1,ans);
     swap(A[ind],A[i]);
}
return;

}
string Solution::solve(string A, int B) {

string ans="";

fun(A,B,0,ans);
return ans;

}