Tricky Permutation(Bactracking)

Question-Given a string containing duplicates, print all its distinct permutations such that there are no duplicate permutations and all permutations are printed in a lexicographic order.

NOTE: DO NOT USE MAP OR SET.

Input Format:
The first and only line of the test case contains the input string.

Solution-

Last test case is giving tle