recursion_Dictionary(Larger)

why my code is failing all the test cases …answer is correct

include

include

using namespace std;

void dict(string str,int i,string out){
//base case
if(str[i]==’\0’){
if(str>out){
cout<<str<<endl;
}
return;
}

//recurseive case
for(int j = i;str[j]!='\0';j++){
    swap(str[i],str[j]);
    dict(str,i+1,out);
   
}

}

int main(){
string str;
cin>>str;
string out = str;
dict(str,0,out);
return 0;
}

hi @abhinavssr2003_eab0717682969e5c u missed backtraking in swapping
and u need to sort and print
updated code https://ide.codingblocks.com/s/667524

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

still not correct #include #include #include using namespace std; void dict(string str,int i,string out){ //base case if(str[i]==’\0’){ if(str>out){ cout<<str<<endl; } return; } //recursive case for(int j = i;str[j]!=’\0’;j++){ swap(str[j],str[i]);//swapping with its own and with other elements dict(str,i+1,out); swap(str[j],str[i]); } } int main() { string str; cin>>str; string out = str; dict(str,0,out); sort(str.begin(),str.end()); return 0; }

The code i gave i working fine it’s tested

just brief me about the last for loop which you used (auto s)

That is same as for (int i=0;i<ans.size();i++)