Do the brackets close properly?
s is made only of the six characters (, ), [, ], { and }.
Return true when every opening bracket is closed by a bracket of the same kind, and brackets close in the reverse order to the one they opened in, so that they nest properly. Return false otherwise.
- Input
s = "{[]()}"- Output
true
[] and () both close inside the braces.
- Input
s = "[(])"- Output
false
The ( opened inside [ must close before the [ does.
- Input
s = "(("- Output
false
Two brackets are opened and never closed.
Limits
1 <= s.length <= 100000s holds only ()[]{}
Hints
Hint 1
Push each opening bracket onto a stack. A closing bracket must match the one on top, which it then removes. At the end the stack must be empty.
Where this was reported
- Zoho, SDE campus interview, 2025 (Medium)
- Ericsson, Software developer interview, 2021 (Code360)
- PhonePe, On-campus interview, 2023 (GeeksforGeeks)
- Wells Fargo, Technology program analyst interview, 2026 (Reddit)
Our own problem on the task these candidates describe; the wording, examples and tests are InternDoor’s.
Run your code to check it on the examples. Submit runs every hidden test.


