Loading...
Loading...
Loading...
A line of code contains only round brackets. Every opening bracket must be closed later, and every closing bracket must match an earlier opening one. Print YES if the line is balanced and NO if it is not.
Example 1
Input
(()())
Output
YES
Every bracket is closed in order.
Example 2
Input
())(
Output
NO
Try the problem first. Open one hint at a time.
Push on (. On ) pop. If there is nothing to pop, the line is not balanced.
At the end the stack must be empty.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor