Compiler (compiler and parser)

whats wrong with my code i have tried everything im also getting the right output but getting WA.
i even tried taking another person solution giving the same input which i have given to my code both are producing same output plz help

my solution:

Your code fails for such input.
Since, we are asked to calculate the length of longest valid prefix. As soon as u see that the number of closing brackets are greater than the number of opening bracket, You should break. Your code is not performing this.
If you want , you can look.

Thanks much appreciated.