Matched Brackets Weird Test Case (ZCO12001)

Okay, so I was able to understand the logic to solve the problem Matched Brackets and I got all test cases correct…except EXACTLY ONE which gives TLE. I cannot understand what is wrong with my code. Here is the solution link and the problem link is given previously. Any help greatly appreciated.