how can I improve my code?
Tle in one the test case
The approach is very similar to that of print permutations. After generating all of the permutations all you need to do is compare your ans with the original number and print only when the ans is lexicograohically smaller than the original String.
see this: