how to resolve this with code
Having TLE issue in this question
Instead of adding elements to the arraylist and then sorting it before printing.
convert the string to a char array. Sort the char array. And then just print the permutations. In this you will save a lot of computation. And the permutations will be sorted