Challenge: Balanced Parentheses

Learn how to balance parentheses.

Problem statement

Write a program to check balanced symbols, such as {}, (), []. The closing symbol should be matched with the most recently seen opening symbol. For example, {()} is legal, {() ({})} is legal, but {((} and {(}) are not legal.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.