Challenge: Check Balanced Parentheses Using Stack

Check if parentheses in a given expression are balanced or not.

Problem Statement

In this problem, you have to implement the is_balanced() function which will take a string containing only curly {}, square [], and round () parentheses. The function will tell us whether all the parentheses in the string are balanced or not.

For all the parentheses to be balanced, every opening parenthesis must have a closing one. The order in which they appear also matters. For example, {[]} is balanced, but {[}] is not.

Input

A string consisting solely of (, ), {, }, [, and ]

Output

It returns True if the expression contains balanced parentheses and returns False otherwise.

Sample Input

exp = "{[({})]}"

Sample Output

True

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