My code is giving tle

ques-- https://hack.codingblocks.com/app/contests/1289/539/problem
cpde- https://ide.codingblocks.com/s/327953

@anubhavb11
You are making a mistake. When you encountered a ‘(’ you inserted it in your output but there is no indication if you have encountered an ‘(’ in the previous states in the current state. Because of no indication, you traverse to the end of the string, return and again get stuck in the while loop. Please correct that. Try solving it through iteration first.

If my answer was able to resolve your query, please mark the doubt as resolved.

i still didnt get it why it stucking in while loop it should traverse i+1 till it wncounter ) then it should traverse fourthe till arr==\0;

@anubhavb11
You should have used iteration at that point. But you have called recursion at the point which is messing things up. First traverse the array and then return from the point instead of making a recursion call.
If my answer was able to resolve your query, please mark the doubt as resolved.