Solution Review: Balanced Parenthesis
Let's discuss in detail the solution to the previous challenge.
We'll cover the following
Solution
-
Traverse the input string. When we get an opening parenthesis, we push it into the stack. When we get a closing parenthesis, we pop a parenthesis from the stack and check if itās the corresponding closing parenthesis.
-
We return
false
if there is a mismatch of parenthesesā¦ -
If we reach the end of the string and the stack is empty, we have balanced parentheses.
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.