![]() |
VOOZH | about |
Given an expression string exp, write a program to examine whether the pairs and the orders of "{", "}", "(", ")", "[", "]" are correct in exp.
Example:
Input: exp = "[()]{}{[()()]()}"
Output: BalancedInput: exp = "[(])"
Output: Not Balanced
👁 check-for-balanced-parentheses-in-an-expression
Algorithm:
Below image is a dry run of the above approach:
Below is the implementation of the above approach:
Balanced
Time Complexity: O(n)
Auxiliary Space: O(n) for stack.
Please refer complete article on Check for Balanced Brackets in an expression (well-formedness) using Stack for more details!