Whats wrong with my code I'm failing two testCases?

Hello Udit,
here is your working code- https://ide.codingblocks.com/s/171578

mistakes
a) you need to pop from stack only when top element of stack matched with pair of current element (input[i])
- example -> if your current value of input[i] is ‘)’ then you will pop from stack only when stack top value is ‘(’ otherwise you need to return false
b) at the end you were returning true if brackets matched correclty but this will fail for cases like (((([])) to handle this you need to check whether your stack is empty or not .if stack is empty then return true otherwise return false.
I hope you find this helpful
regards
Aman yadav

Thanks for helping me out.

1 Like