Solution Review: Balanced Parenthesis

Let's discuss in detail the solution to the previous challenge.

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 70+ hands-on prep courses.