04 Try it yourself Interactive

Watch the stack eat the array

The same job, two ways, on the same list. Brute force re-scans the tail from every position. The monotonic stack scans once and pops. Watch the stack column on the right and the comparison counter at the bottom.

Brute force · nested scan
O(n²) — rescans the tail
2–9 whole numbers (0–99), commas or spaces.
Stack · empty
answer
Press Next to begin. Each press moves one step.


      
Current i
Scanning j
Answers settled0
Comparisons0
step 0 / 0