Recursion smaller dictionary order

why is that program is passing all the test cases when i am commenting out the Backtrack case and the sorting operations in the main which i was doing to form the desired result.
Why is it so that on avoiding backtracking my answer is correct? it should not be correct as on avoiding backtracking in case of string permutations the string is changed for subsequent calls while returning…

pls give reason for thiss that why we are not backtracking…???

Basically, here you need not to print the 8 permutations possible for a cab string as given in sample case, but you need only those combinations for which the output permutations are less than input , thus backtracking is not required here, and also you can use sort function, but it will not produce the output in desired format, thus you need to exclude that also