Mental Model
We use a stack to keep track of bars that are not yet processed for largest rectangle. When a smaller bar comes, we calculate areas for taller bars before it.
Analogy: Imagine stacking books by height. When a shorter book arrives, you remove taller books from the top to find the biggest flat surface you can make with the books below.
Histogram bars: heights = [2, 1, 5, 6, 2, 3] Index: 0 1 2 3 4 5 Stack stores indices of bars in increasing height order. Example stack: bottom [0, 2, 3] top Each step we compare current bar height with top of stack height.