Source invariant: "A stack remembers the most recent unresolved opener — exactly what bracket nesting needs; a shadow stack of running minima makes getMin O(1)."
2. What must the helper stack track?
Source invariant: "A stack remembers the most recent unresolved opener — exactly what bracket nesting needs; a shadow stack of running minima makes getMin O(1)."
3. When should Daily Temperatures pop?
Source invariant: "Keep the stack sorted; when a new element breaks the order, everything you pop just found its next-greater/next-warmer answer. Each index is pushed and popped once, so O(n)."
4. Spot the bug: histogram code pops on taller current bars.
Source invariant: "When a shorter bar appears, each taller bar you pop can no longer extend right, so finalize its rectangle. (Hard — go slow.)"
5. For subtraction, why name first pop b?
Source invariant: "Push operands; on an operator, pop two, combine, push the result — postfix needs no precedence rules."
6. Why can monotonic-stack loops stay O(n)?
Source invariant: "Keep the stack sorted; when a new element breaks the order, everything you pop just found its next-greater/next-warmer answer. Each index is pushed and popped once, so O(n)."
Self-check gate
Pass tonight if all three are true
You attempted at least two problems from a blank file inside the 45-minute timer.
At least one attempted problem was monotonic stack.
Before coding each problem, you explained the pattern name and time/space complexity aloud.
If you fail the gate, add the failed problem to the next revision. If the failure was pattern choice, add Daily Temperatures. If it was opener matching or minima, add Valid Parentheses or Min Stack. If it was operand order, add Evaluate Reverse Polish Notation.