Why my code is giving tle https://ide.codingblocks.com/s/580647

please check my code

You are getting a TLE as you are iterating over the entire string for every recursive call. For every recursive call you can simply check if the element at vidx is equal to ‘x’.
If yes, then you can send it to the end just like you did it in your code.
If no, the simply move to the next element.
In simpler terms. Try removing the for loop from your code.

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.

still not getting the desired ans

https://ide.codingblocks.com/s/580647 by removing the loop not getting the desired ans

Every recursive call is returning you a String, you need to capture this result and then return this result or else the result will get lost. You are returning the str which is a local variable for each recursive call. Instead you need to store the result of further recursive calls and include them in the result.
I have made corrections in your code and added the comments too. Give it a check.

thanks a lot for helping

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.