WA in the problem COMPILER

Here is my solution to the problem COMPILER
https://www.codechef.com/viewsolution/25463566

I am getting WA for this problem. I think that the problem is somewhere with the way i am using the max variable. But i cant figure it out…!!!

Case like : <>< gives 0 in your code whereas output should be 2.

Reason : You assume answer to be correct only if at last flag <= 0 . Here flag at last would be = 1 (> 0 ) but your code does not think that it is a correct answer.

Better strategy would be - Everytime you see your flag becomes = 0 ; you should conclude that it is a valid parenthesis and you should update max.

1 Like