The sample output is coming out correct but test cases are failing

hello @pranaynigam

in line 31, it is not n , it should be the test case number

still test cases are giving TLE. i even changed my way of checking for “bb”.

dont genrate all perumuations and then check whether string is valid or not.
instead genrate only valid permuattion.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.