152. Balanced Brackets
Core1000 ms256 MBSolved by 0%
Read one line containing (, ), [, ], { and }, and print Yes
if the brackets are balanced or No otherwise.
Now the TYPE matters as well as the count — ([)] is not balanced, because the bracket
being closed is not the one most recently opened.
An empty line counts as balanced.
Constraints - The line has between 0 and 100000 characters. - Only the six bracket characters appear.
Input
A single line containing only the characters ( ) [ ] { }. It may be empty.
Output
Print exactly one word: Yes or No. An empty line is balanced.
Input{[()]}
OutputYes
Notenests all three bracket types correctly
Input([)]
OutputNo
Notehas matching counts but the wrong nesting order, which a counter cannot detect
Hint 1Approach
Hint 2Approach
Hint 3Pseudocode
Hint 4Full solution