Permutation of string backtracking


why my code not work for permutaions of string?

Hello @AjayRRJ,

I have corrected your code for infinite outputs:

But, it will produce wrong output.
Reason:
Given a string containing duplicates, print all its distinct permutations such that there are no duplicate permutations
Read the question properly.

Let me know if you face any problem.
Hope, this would help.
Give a like if you are satisfied.

1 Like

yes can please modify my code for duplicacy


now my code is correct or not?

Hey @AjayRRJ,

I have modified it:

Let me know if you do not understand something.

Hope, this would help.

not understand this code line meaning
while(out[i]==s){
i++;
}
i=i-1;

Hey @AjayRRJ,

As i have first sorted the vector before calling this function.
So, The duplicate values are present at continuation index.
Thus, after printing s,
We ignore the duplicates.

Hope, this is clear now.