Problem
You get a string s that contains only the characters (, ), [, ], { and }. Return true if the brackets in s are valid. Return false if they are not.
The brackets are valid when all these rules are true:
A closing bracket of the same type closes each opening bracket. The brackets close in the correct order, so the last open bracket closes first. Each closing bracket has a matching opening bracket before it.
Example 1
- Input:
- s = "{[]()}"
- Output:
- true
- Explanation:
- Each opening bracket has a closing bracket of the same type, in the correct order.
Example 2
- Input:
- s = "[(])"
- Output:
- false
- Explanation:
- The
]comes while(is still open. The(must close first.
Example 3
- Input:
- s = "(("
- Output:
- false
- Explanation:
- The two opening brackets have no closing brackets.
Constraints
- 1 <= s.length <= 10^4
- s contains only the characters ()[]{}.
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Longest Valid Parentheses
Coding · Bracket Sequences · Dynamic Programming · Stack
- Maximum Nesting Depth of Two Valid Parentheses Strings
Coding · Bracket Sequences · Stack · String
- Minimum Add to Make Parentheses Valid
Coding · Bracket Sequences · Greedy · Stack
- Maximum Nesting Depth of the Parentheses
Coding · Bracket Sequences · Stack · String
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 9 records
Amazon
Leetcode 20. Valid Parentheses
Reported Jun 10, 2026 · 2 source reports
INTERN
Source snapshot: Nov 12, 2026
View sourceApple
Leetcode 20. Valid Parentheses
Reported Apr 7, 2026 · 4 source reports
MID_LEVEL, SENIOR
Source snapshot: Nov 12, 2026
View sourceGoogle
Leetcode 20. Valid Parentheses
Reported Dec 25, 2024 · 2 source reports
MID_LEVEL
Source snapshot: Nov 12, 2026
View sourceIntuit
Leetcode 20. Valid Parentheses
Reported Sep 19, 2025 · 1 source report
SENIOR
Source snapshot: Nov 12, 2026
View source