my code is working for sample test case but displaying wrong answer in other testcases.
Displaying wrong answer for test cases
The error in your code is that it is not displaying the permutations in a sorted order, while it’s mentioned in the question that you need to display them in a sorted order, so the solution can be that, instead of printing the permutation in the base case, you push it into the vector, and at the end, sort the vector and print it.