intro practice · coding problem
Valid parentheses with a stack
Implement isValid(s) for brackets ()[]{} using a stack.
The mechanism
A stack is last-in-first-out: the last thing you pushed is the first thing you pop. Reach for one when the natural question is "what was the most recent unfinished thing?" — parsing, recursion, undo, matching brackets.
Expected evidence
isValid("()[]{}") true; isValid("(]") false.Try this drill in the practice workspace →
Hints when you need them
- Push opens; pop must match close.
- Stack empty at end.