Optimal Algorithmic Approach
Monotonic Stack: popping reveals the left boundary for each bar.
Core Invariants & Edge Cases
- Use a monotonic increasing stack of bar indices
- When a shorter bar is encountered, pop and calculate width from previous stack top
- Append a sentinel bar of height 0 to flush the stack at the end