How much rain sits on an elevation map? From scanning left and right for every bar (O(n²)), to precomputed prefix and suffix maxima (O(n) time, O(n) space), to two pointers that carry the running maxima in O(1) space, with the reason the smaller side is always safe to settle. Then the stack view, a 2D map with a heap, and running maxima in ML monitoring.
about 10 min 4 Python examples 2 quick checks
Problem.height[i] is the height of a bar of width 1. After rain, how many units of water are trapped?
ML context. The core quantity is the running maximum from each side: "the highest point seen so far". The
same prefix/suffix aggregate shows up when you track best-so-far validation loss for early stopping, compute the
drawdown of a metric (how far it has fallen from its previous peak), or find regressions in a dashboard. The
two-pointer trick shows how to get both sides' maxima without storing either array.
1. Step 1: Clarify
That's the preview. Modules 00–01 are free; this lesson is part of Unrolled Pro.
Staff AI & Pro Tier Lesson
Unlock "Trapping Rain Water"
The foundations are free forever. Unrolled Pro unlocks the complete lesson, production architectures, and 55 battle-tested ML system design case studies.
Everything included with Pro:
All 234+ Deep-Dive Lessons across transformer internals, inference, RAG & agents
55 Staff-Level ML & System Design Case Studies with mathematical capacity estimates
AI Engineer Sheet & Exercises with worked solutions, self-checks, and code
100 Landmark Research Papers guided walkthroughs & progress tracking
14-Day Money-Back Guarantee — 100% full refund if you aren't satisfied