Loading...
Loading...
Loading...
A line of code has round, square and curly brackets and other characters. Brackets must close in the reverse order they were opened, and each closer must match its opener. Print YES if the line is valid and NO if not. Other characters are ignored.
Example 1
Input
{[()]}Output
YES
Valid.
Example 2
Input
([)]
Output
NO
Try the problem first. Open one hint at a time.
Map each closer to its opener in a dict.
A closer needs a non-empty stack whose top is the matching opener.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor