Valid Brackets
EasyPractice library · +10 XPstackstrings
A string made only of the characters ( ) [ ] { } is valid when every opening bracket is closed by a bracket of the same type, and brackets are closed in the right order.
Print YES if the string is valid and NO otherwise.
Input
One line: the string s.
Output
YES or NO.
Constraints
- 1 <= |s| <= 200000
sonly contains()[]{}
Time limit 1 s (native code; slower languages get more)Memory 256 MB12 hidden tests
Example 1
Input
()[]{}
Output
YES
Every bracket is closed in order.
Example 2
Input
([)]
Output
NO
The square bracket is closed while a round one is still open.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
Example 1 input
()[]{}
Example 2 input
([)]