I can't understand why my code is wrong? It's in C++. Please, help!


#1

What is wrong with my solution?

void answer(string &result, string &A, int B, int curr){
    int l=A.length();
    if(B==0 || curr>=l){
        if(A>result){
            // cout<<A<<endl;
            // cout<<A<<" "<<result<<endl;
            result=A;
        }
        return;
    }
    // char c=A.at(curr);
    for(int i=curr+1;i<l;i++){
        if(A.at(i)<=A.at(curr)){
            // A.at(curr)=A.at(i);
            // A.at(i)=c;
            swap(A[curr],A[i]);
            answer(result,A,B-1,curr+1);
            swap(A[curr],A[i]);
            // A.at(i)=A.at(curr);
            // A.at(curr)=c;   
        }
    }
    answer(result,A,B,curr+1);
}

string Solution::solve(string A, int B) {
    string result=A;
    answer(result,A,B,0);
    return result;
}