Help in debugging for Matched Brackets

Hey everyone,
I was solving Matched Brackets problem from DSA learning series (week 2)
Problem Link : CodeChef: Practical coding for everyone

I solved it using stacks , and I am getting correct answer for sample input, but its not passing all the cases . I tried some more examples , they are giving correct answers.
I am not understanding in which case can my code gives incorrect answer.

( Also, the problem lies in finding depth. I have seen editorial , where they decreased depth value when “)” is encountered, but I am not getting why my approach is failing
Any help would be appreciated)

Code - CodeChef: Practical coding for everyone

Your solution is giving wrong answer on input :-

10
1 1 1 2 1 1 2 2 2 2

correct answer is 4 6 10 1

1 Like

Oh I get it now , thank you so much.
I was struggling for days .