Concept Flow - Largest Rectangle in Histogram Using Stack
Start with empty stack
Iterate over bars by index
While stack not empty and current bar height < height at stack top
Pop from stack
Calculate area with popped bar as smallest
Update max area if larger
Push current index to stack
Repeat until all bars processed
Pop remaining bars from stack and calculate area
Return max area found
We scan bars left to right, using a stack to keep indexes of bars in ascending height order. When a lower bar appears, we pop taller bars to calculate areas, updating max area.
