Mental Model
We use a stack to keep track of bars that are not yet processed for the largest rectangle. When we find a bar shorter than the top of the stack, we calculate areas with the bars popped from the stack.
Analogy: Imagine stacking books by height. When a shorter book comes, you remove taller books from the stack to find the biggest flat surface you can make with the books below.
Histogram bars: height _ _ _ _ | | | || || | | | _ | || || | | || || || || | | || || || || | 0 1 2 3 4 (indices) Stack stores indices of bars in increasing height order.
