Step 1: Push index 0 (height 2) onto stack
Stack: [0]
Heights: 2,1,5,6,2,3
Why: Stack is empty, so push first bar index
Step 2: Current height 1 is less than height at stack top (2), pop index 0 and calculate area
Popped index 0 (height 2), width = current index 1 - stack empty => width=1
Area = 2*1=2
Stack: []
Why: Found a smaller bar, so calculate area for taller bars before it
Step 3: Push index 1 (height 1) onto stack
Stack: [1]
Heights: 2,1,5,6,2,3
Why: Stack empty or current height >= top height, so push
Step 4: Push index 2 (height 5) onto stack
Stack: [1, 2]
Heights: 2,1,5,6,2,3
Why: Current height 5 >= height at top (1), push index 2
Step 5: Push index 3 (height 6) onto stack
Stack: [1, 2, 3]
Heights: 2,1,5,6,2,3
Why: Current height 6 >= height at top (5), push index 3
Step 6: Current height 2 is less than height at stack top (6), pop index 3 and calculate area
Popped index 3 (height 6), width = current index 4 - stack top index 2 - 1 = 1
Area = 6*1=6
Stack: [1, 2]
Why: Smaller bar found, calculate area for taller bars
Step 7: Current height 2 is less than height at stack top (5), pop index 2 and calculate area
Popped index 2 (height 5), width = current index 4 - stack top index 1 - 1 = 2
Area = 5*2=10
Stack: [1]
Why: Continue popping taller bars to find max area
Step 8: Push index 4 (height 2) onto stack
Stack: [1, 4]
Heights: 2,1,5,6,2,3
Why: Current height 2 >= height at top (1), push index 4
Step 9: Push index 5 (height 3) onto stack
Stack: [1, 4, 5]
Heights: 2,1,5,6,2,3
Why: Current height 3 >= height at top (2), push index 5
Step 10: Reached end, pop remaining bars and calculate areas
Pop index 5 (height 3), width = 6 - 4 - 1 = 1, area=3*1=3
Pop index 4 (height 2), width = 6 - 1 - 1 = 4, area=2*4=8
Pop index 1 (height 1), width = 6 - stack empty => width=6, area=1*6=6
Stack empty
Why: Calculate areas for remaining bars to find max
Result: Largest rectangle area = 10
Final stack empty