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 needed
Push current index to stack
After iteration, pop remaining bars
Calculate area for each popped bar
Update max area if needed
Return max area
We scan bars left to right, using a stack to keep indexes of bars in ascending height. When a lower bar appears, we pop taller bars to calculate areas, updating max area.