#K6806. Balanced Parentheses Check
Balanced Parentheses Check
Balanced Parentheses Check
You are given multiple expressions containing only the characters (')
, )
, {}
and []
. Your task is to determine whether each expression has balanced parentheses.
An expression is said to be "balanced" if all opening brackets are properly matched and closed by the corresponding type of closing brackets in the correct order. For any expression E
, it is balanced if:
- Every opening bracket \( ( \), \( { \) or \( [ \) has a corresponding closing bracket \( ) \), \( } \) or \( ] \) respectively.
- The pairs of brackets are properly nested.
For example, the expression ([]{})
is balanced, while ([)]
is not.
inputFormat
The first line of input contains an integer T
representing the number of test cases. Each of the following T
lines contains a string consisting solely of the characters (')
, )
, {}
and []
.
outputFormat
For each test case, print a single line containing YES
if the expression is balanced or NO
otherwise.
3
([]{})
([)]
((()))
YES
NO
YES
</p>