Step 1: Push index 0 (height 2) onto stack
Stack: [0]
Heights: 2, 1, 5, 6, 2, 3
Why: Start with first bar, stack keeps indices of bars with increasing heights
Step 2: Current bar height 1 is less than height at stack top (2), pop index 0 and calculate area
Popped index 0 (height 2), calculate area = 2 * 1 = 2
Stack: []
Why: Found a smaller bar, so calculate area for taller bars before pushing smaller one
Step 3: Push index 1 (height 1) onto stack
Stack: [1]
Heights: 2, 1, 5, 6, 2, 3
Why: Stack empty, push current index
Step 4: Push index 2 (height 5) onto stack
Stack: [1, 2]
Heights: 2, 1, 5, 6, 2, 3
Why: Current bar taller than top of stack, push index
Step 5: Push index 3 (height 6) onto stack
Stack: [1, 2, 3]
Heights: 2, 1, 5, 6, 2, 3
Why: Current bar taller than top of stack, push index
Step 6: Current bar height 2 is less than height at stack top (6), pop index 3 and calculate area
Popped index 3 (height 6), area = 6 * 1 = 6
Stack: [1, 2]
Why: Calculate area for bar taller than current smaller bar
Step 7: Current bar height 2 is less than height at stack top (5), pop index 2 and calculate area
Popped index 2 (height 5), area = 5 * 2 = 10
Stack: [1]
Why: Calculate area for bar taller than current smaller bar
Step 8: Push index 4 (height 2) onto stack
Stack: [1, 4]
Heights: 2, 1, 5, 6, 2, 3
Why: Current bar taller than top of stack, push index
Step 9: Push index 5 (height 3) onto stack
Stack: [1, 4, 5]
Heights: 2, 1, 5, 6, 2, 3
Why: Current bar taller than top of stack, push index
Step 10: Reached end, pop remaining bars and calculate areas
Pop index 5 (height 3), area = 3 * 1 = 3
Pop index 4 (height 2), area = 2 * 4 = 8
Pop index 1 (height 1), area = 1 * 6 = 6
Stack: []
Why: Calculate areas for all remaining bars to find max
Result: Largest rectangle area = 10
Final stack empty