Balanced brackets
A string contains only the brackets ( ) [ ] { }. Print YES if every bracket is closed by the right type in the right order, otherwise NO.
Reported in: Infosys (2021–26), HCLTech (memory-based)
Input
One line: the bracket string.
Output
YES or NO.
Constraints
1 ≤ length ≤ 10^5.
Example 1
Input:
{[()]}()
Output:
YESExample 2
Input:
([)]
Output:
NOHint: Push opening brackets on a stack; each closing bracket must match the top.