Easystackstrings
Balanced Brackets
A config parser only accepts expressions whose brackets are properly balanced. Given a string made only of the characters ( ) [ ] { }, decide whether every opening bracket is closed by the matching bracket type, in the correct order.
Input
One line containing the string s.
Output
Print YES if s is balanced, otherwise NO.
Constraints
- 1 ≤ |s| ≤ 10^4
- s contains only ( ) [ ] { }
Sample 1
Input
{[()()]}
Output
YES
Every bracket closes in the right order.
Sample 2
Input
([)]
Output
NO
The ( is closed by ] before its own ) arrives.
Time limit 2s (3s for Python in the browser). Your code runs on your device, so timings vary a little between machines.