Day 20 — Revision: Stack week

Revision day · stack matching · monotonic stack · stack evaluation

Tonight's goal: pick your three weakest stack problems from the menu, re-solve each from a blank file with no hints, and keep the monotonic-stack invariant sharp.

Tonight's protocol

Use the revision-day protocol: blank file, no hints, and only run one or run two can count.

  1. 0:00–0:04: answer the warm-up MCQs in one pass. Do not study explanations yet.
  2. 0:04–0:05: pick your three weakest problems from the menu. Choose the three you least want to face tonight.
  3. 0:05–0:25: problem 1. Say the pattern name, invariant, brute force, and target complexity before coding.
  4. 0:25–0:45: problem 2. Open a fresh blank file; no notes, hints, stored code, or videos.
  5. 0:45–1:05: problem 3. Stop judging after the second run, even if you continue debugging.
  6. 1:05–1:15: compare only failed or shaky attempts. Write WA: <root cause> for each miss.

The problem menu

Pick your three weakest from this menu, re-solve from a blank file, no hints.

ProblemPattern nameTonight's first sentence
Valid Parentheses Stack matching The newest unresolved opener must close first.
Min Stack Shadow minima stack Every depth stores the minimum at that depth.
Daily Temperatures Monotonic stack: next warmer A warmer day resolves older colder days.
Next Greater Element I Monotonic stack: next greater A greater value resolves smaller waiting values.
Largest Rectangle in Histogram Monotonic stack: finalize on shorter bar A shorter bar finalizes taller rectangles.
Evaluate Reverse Polish Notation Stack evaluation An operator combines the top two operands.

Warm-up MCQs

1. Which invariant belongs to Valid Parentheses?

2. For Min Stack, what must every push record?

3. When a new element breaks monotonic order, what happens?

4. In the histogram problem, when do taller bars pop?

5. In postfix evaluation, an operator arrives. What happens?

6. Why can a monotonic stack stay O(n)?

Self-check gate

Pass tonight if

At least two of your three chosen problems pass on run one or run two, and you can explain the monotonic-stack invariant without looking: keep the stack sorted; a breaking element makes popped items ready; each item is pushed and popped at most once.

If you miss the gate, do not erase the evidence. Add every failed problem to the next revision list with one root-cause line: wrong invariant, wrong pop condition, wrong operand order, missing empty-stack case, or missed edge case. Then compare with the source lesson for that exact problem.