Getting TLE in Tricky permutations

I am getting TLE in last test case .
here is my code:-
https://ide.codingblocks.com/s/69681

Hi

approach you are using in to check if the generated string exists or not, is linear (in generate fucntion) you can optimise this by using binary search instead of this, you can maintain a sorted list of permutation generated and then do a binary search on that, this will decrease the time complexity.

Hit like if you get it.