Redundant parentheses

i did the dry run and i m getting the right ans , but it is giving wrong ans , please tell me what is wrong in it

The logic is incorrect. The checking for true or false needs to be done when you encounter a closing bracket. How ? Just push the indices of open brackets on stack and keep 2 variables which store the indices of the last matched pair of braces. Now when you encounter a ‘)’ pop index of opening bracket from stack and check if this matched pair just enclosed the last matched pair.

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.