Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Keep indices of bars in increasing-height order. When a shorter bar appears, repeatedly pop taller bars and compute rectangle area where the popped bar is the limiting height. Use a trailing zero height to flush remaining bars.
When a bar is popped, the current index is the first smaller bar on the right and new stack top is first smaller bar on the left, giving exact maximal width for that height.
Updated Feb 2026