How to prun the height of tree or stop our recursion when the work is completed?

I have solved this problem by finding all permutation of the string, but I want to stop the recursion-computing after which I have found the kth smallest permutation. Any Suggestion?
Thanks in advance :’)

Hi Tushar,
But don’t you think find all the permutation of the string upto the Kth position can cause TLE?
Since, K can go upto 18!.
Think of some other way to solve this problem.

Okay I am thinking for another approach @virali-crio-ta.

Closing this topic as your issue is resolved by the mentor. If it is still not resolved, Kindly un-mark the accepted solution or create a new topic and post this question as a reference link in the description of the new topic.