#K6946. Balanced Brackets Checker
Balanced Brackets Checker
Balanced Brackets Checker
You are given a series of strings consisting solely of the characters: '(', ')', '{', '}', '[' and ']'. Your task is to determine whether each string is balanced. A string is considered balanced if:
- Every opening bracket has a corresponding closing bracket of the same type.
- The brackets are closed in the correct order.
An empty string is also considered balanced.
For example, the string ([]{})
is balanced while ([)]
is not. Your program should output YES
for a balanced string and NO
otherwise.
inputFormat
The first line of input contains an integer n
representing the number of test cases. Each of the following n
lines contains a single string consisting of brackets.
Example:
3 ([]{}) ([)] ({}[()])
outputFormat
Output exactly n
lines. For each test case, print YES
if the string is balanced, or NO
if it is not.
Example:
YES NO YES## sample
3
([]{})
([)]
({}[()])
YES
NO
YES
</p>