#K94717. Balanced Brackets
Balanced Brackets
Balanced Brackets
You are given a string s
consisting solely of the characters '(', ')', '{', '}', '[' and ']'
. Your task is to determine if the string is balanced. A string is considered balanced if:
- Every opening bracket has a corresponding closing bracket of the same type.
- Brackets are closed in the correct order.
In formal terms, if we define the property of being balanced as:
$$\text{balanced}(s) \iff \text{for every opening bracket, there is a corresponding closing bracket in the correct order}$$then your program should output True
if the string is balanced and False
otherwise.
inputFormat
The input consists of a single line containing the string s
. The string may be empty and will include only the characters '(', ')', '{', '}', '[' and ']'
.
outputFormat
Output a single line: True
if the string is balanced; otherwise, output False
.
{[()]}
True