Dictionary order smaller test case not passing

I am returning all the permutations of string stored in arraylist to main.
And then in main I’m comparing each permutaion to my original string using compareTo() ,if it is smaller then it is printed.

I’m getting the correct ressult but 2 test cases are not passing.

Hi Ayush,
Send your code.

Hi Ayush,
Your code is not sorting the strings properly as
for input: 1234
correct output is :
1234
1243
1324
1342
1423
1432

where as your code is giving output:
1234
1324
1342
1243
1423
1432

since you are using arraylist you can use library function to sort the list i.e. Collections.sort(res)

I’m not sorting, I’m just printing the permutation as computed by the algorithm if it is smaller in order.
Moreover why will the string 1234 produce any output, it is already the smallest.

And could you please explain on what basis the order of output for “cab” is -
ACB
ABC
BCA
BAC

It is not in lexicographical order.

Hi Ayush,
Actually the input was 2134.