#K11646. Balanced Parentheses Checker
Balanced Parentheses Checker
Balanced Parentheses Checker
Given a string S containing only the characters (')
, ')'
, '{'
, '}'
, '['
, and ']'
, determine if the parentheses in the string are properly nested and balanced. A string is considered balanced if all open brackets have corresponding matching closed brackets in the correct order.
The problem can be formulated as follows: \[ \text{isBalanced}(S) = \begin{cases} \text{True} & \text{if } S \text{ is empty or every opening bracket has a matching closing bracket in the correct order},\\ \text{False} & \text{otherwise.} \end{cases} \]
For example, the string "{[()]}" is balanced, while "{[(])}" is not.
inputFormat
The input consists of a single line containing the string S (possibly empty) which is composed solely of the characters '(', ')', '{', '}', '[' and ']'.
outputFormat
Output a single line containing either True
if the string is balanced, or False
if it is not.
{[()]}
True
</p>