DSA & Implementation · intro
Stack
LIFO, parsing, monotonic stack.
Mental model
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.
How to study Stack
Begin by restating the mental model in your own words, then connect it to a concrete system you have built or operated. Name the mechanism, the constraint it addresses, and the trade-off it introduces. Use Stack (Wikipedia) to check details, but close the source before writing your explanation. Retrieval is the learning step; rereading is only preparation.
Next, compare Stack with the neighboring concepts in its roadmap. Ask what changes in correctness, latency, resource use, operability, and failure recovery. Complete Valid parentheses with a stack, Valid Parentheses, Daily Temperatures and preserve the command, input, output, and one failed attempt as evidence. Finish by explaining the idea without jargon to someone who has not studied the track.
Proof of understanding
- Explain the mechanism from first principles and identify the state it reads or changes.
- Give one situation where the concept is the right choice and one where it is not.
- Predict a realistic failure mode before running the drill, then compare the prediction with evidence.
- Connect the result to a roadmap or build artifact instead of treating the concept as isolated trivia.
Learn from primary sources
- Stack (Wikipedia) (doc)
Practice and explain it back
Valid parentheses with a stack
Implement isValid(s) for brackets ()[]{} using a stack.
Expected evidence: isValid("()[]{}") true; isValid("(]") false.
Open the interactive drill →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/
Expected evidence: Pass all LeetCode test cases for this problem.
Open the interactive drill →Daily Temperatures
LeetCode #739 — Daily Temperatures. Solve on LeetCode, then implement here if you want it in your drill queue. https://leetcode.com/problems/daily-temperatures/
Expected evidence: Pass all LeetCode test cases for this problem.
Open the interactive drill →Car Fleet
LeetCode #883 — Car Fleet. Solve on LeetCode, then implement here if you want it in your drill queue. https://leetcode.com/problems/car-fleet/
Expected evidence: Pass all LeetCode test cases for this problem.
Open the interactive drill →Review prompts
- In a monotonic stack, what does the stack hold at any moment, and what does a pop mean?
Build evidence
Use a roadmap capstone to turn this concept into working evidence.
Prerequisites
Related concepts
None assigned yet.