All problems
easy · 409 tests
Balanced Brackets
A string of brackets ()[]{} is balanced when every opening bracket is closed by the same kind of bracket in the correct order. For each of t strings, print YES if it is balanced and NO otherwise.
Input
Line 1: t (1 <= t <= 1000).
Then t lines, each a non-empty string of length up to 10^5 made only of ()[]{}.
Output
t lines, YES or NO.
Samples
Input 1
1
()[]{}
Output 1
YES
Input 2
1 ([)]
Output 2
NO
Input 3
1
{[]}
Output 3
YES
Input 4
1 ((
Output 4
NO
Scoring
- Basic correctness20 pts
- Edge cases15 pts
- Random small20 pts
- Random large15 pts
- Adversarial10 pts
- Performance20 pts
2s · 256 MB