One test case showing TLE

One test case showing TLE but it is the most efficient method that I know.

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

I have already done that. I have passed a sorted string as argument and also the arraylist is used only for removing any duplicacy of string permutations

using a HashMap instead of ArrayList solved the TLE error

1 Like