#K9791. Balanced Parentheses Check
Balanced Parentheses Check
Balanced Parentheses Check
Given a string consisting solely of the characters '(', ')', '{', '}', '[' and ']', determine whether the string is balanced. A string is balanced if every opening bracket has a corresponding closing bracket in the correct order.
In mathematical terms, if we denote the set of brackets as ( { ( , ) , { , } , [ , ] } ), the string is balanced if for every prefix of the string, the number of opening brackets is at least the number of closing brackets, and the total count of each type of bracket matches exactly.
inputFormat
The input consists of a single line containing a non-empty string of characters, each being one of: '(', ')', '{', '}', '[' or ']'. For example: "[()]{}{()()}".
outputFormat
Output a single line containing either 'True' if the string is balanced, or 'False' if it is not.## sample
()
True