Given a string `s` containing just `()[]{}`, determine if the brackets are balanced — every opener has a matching closer in the correct order.
Example: s = "([{}])" → true
Stack: Push openers; on a closer, the stack top must be its matching opener. (time O(n), space O(n))
No visualization loaded.
Watch
—
i
Press Run to begin.
0/0
Why the best approach wins
A stack is the natural fit: the most recently opened bracket must be the first to close (LIFO). Each character is pushed/popped at most once, so it's a single O(n) pass.
Stack: O(n) time / O(n) space
Your turn — implement isValid
Loading editor…