Community Article

Monotonic Stack: The Pattern Everyone Skips

The next-greater-element trick that turns O(n^2) scans into O(n). Daily temperatures, largest rectangle in histogram, and trapping rain water, all from the same shape.