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
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.
Hint 1Where to start
Hint 2The approachOpen hint 1 first. This one carries on from it.
Hint 3PseudocodeOpen hint 2 first. This one carries on from it.
Hint 4Full solutionOpen hint 3 first. This one carries on from it.