All tasks
Mediumstackstrings

Balanced Brackets

Time limit 2 s · Memory 64 MBAcceptance: —Solved by: 0

Statement

You are given a string made only of ( ) [ ] { }. Print YES if the brackets are balanced (every opening bracket is closed by the matching type in the correct order), otherwise NO.

Examples

Example 1
Input
()[]{}
Output
YES
Example 2
Input
([)]
Output
NO

Constraints

  • String length is between 1 and 10^5
Solve this task to unlock the editorial.

AI tutor

Stuck? Get a nudge — the tutor explains the idea, it never hands you the solution.