151. Balanced Parentheses
Core1000 ms256 MBSolved by 0%
Read one line containing only ( and ) and print Yes if the brackets
are balanced, or No otherwise.
Balanced means every opening bracket has a matching closing one, in the right order. So
(()) is balanced and )( is not.
An empty line counts as balanced.
Constraints - The line has between 0 and 100000 characters. - Only `(` and `)` appear.
Input
A single line containing only ( and ). It may be empty.
Output
Print exactly one word: Yes or No. An empty line is balanced.
Input(())
OutputYes
Noteis properly nested
Input(()
OutputNo
Noteleaves one bracket open at the end, which a counter reaching zero would miss
Hint 1Approach
Hint 2Approach
Hint 3Pseudocode
Hint 4Full solution