#C12742. Balanced Parentheses Checker
Balanced Parentheses Checker
Balanced Parentheses Checker
Given a string that may contain round (()
), square ([]
), and curly ({}
) parentheses along with other characters, determine whether the parentheses in the string are balanced.
A string is said to be balanced if:
- Every opening parenthesis has a corresponding closing parenthesis.
- The order of the parentheses is correct.
For example, the string {[()]}
is balanced but {[(])}
is not. Note that non-parentheses characters should be ignored.
Use an efficient algorithm based on a stack to solve the problem.
inputFormat
The input consists of a single line containing the string to be checked. The length of the string is at most \(10^5\) characters.
outputFormat
Output a single line with True
if the string is balanced, and False
otherwise.
True