Please help with the logic

i am unable to think of a logic, please help

its a simple application is stackā€¦ all u have to do is if u encounter ) and check if character present on top of stack is ( then it contains redundant bracketsā€¦ refer to my code https://ide.codingblocks.com/s/605225

yes, i got it, i have dry ran it myself, but i am unable to understand the logic, why it works?, please help explain

what logic are u unable to understandā€¦ try to dry run my codeā€¦ u will get itā€¦

i hope ur doubt is cleared now

What i s the logic behind this approach, I have done the dry run twice and can see that the ans is correct but why is this approach working, I can see 2+2 =4 but i want to understand how i.e. 2+1 = 3 and 3+1 = 4 and that how 2 + 2 =4, can u tell me the logic?

what are u saying?? what 2+2 =4, 2+1 = 3 and 3+1 = 4, 2 + 2 =4 are u taking aboutā€¦ this is just a simple ques with implementation of stackā€¦

u still have any doubt?? or shall i mark this doubt as resolved???

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.