← All coding problems
Valid Parentheses
easyStack & Queue+10 XPTime limit 2s
A string of brackets ()[]{} is valid if every opening bracket is closed by the same type of bracket, in the correct order.
Input: one line s made only of ()[]{}.
Output: true if s is valid, otherwise false.
Constraints: 1 ≤ length of s ≤ 10⁵.
Sample input 1
()[]{}
Sample output 1
true
Sample input 2
(]
Sample output 2
false
📖 Stuck? Learn the pattern
Read input from standard input and print the answer to standard output. Your code runs in a secure sandbox against the samples (Run) and hidden tests (Submit).