intro practice · coding problem

Valid Parentheses

LeetCode #20 — Valid Parentheses. Solve on LeetCode, then implement here if you want it in your drill queue. https://leetcode.com/problems/valid-parentheses/

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.

Study Stack

Expected evidence

Pass all LeetCode test cases for this problem.

Try this drill in the practice workspace →

Hints when you need them
  • Pattern hint: stack.
  • Start with brute force, then optimize time/space.
  • Write down invariants before coding.

Check the sources

Practice the same mechanism

Browse all practice briefs