Largest Rectangle in Histogram, five ways

Try:
CALL
1 / 1

Code

The highlighted line runs next. The pill shows the live values in the running call.

Cost

Work done so far, and how the five solutions compare

Histogram

Filled: the rectangle being measured. Green outline: best so far

Keyboard: ← → step, Space play or pause. 1 to 12 bars with heights 0–20. In the divide & conquer trace, the segment-tree query itself is shown as one step (it costs O(log n)); the code for it is in full on the left.