Code
The highlighted line runs next. The pill shows the live values in the running call.
Cost
Work done so far, and how the two solutions compare
Bars
Water fills up to the shorter wall
The highlighted line runs next. The pill shows the live values in the running call.
Work done so far, and how the two solutions compare
Water fills up to the shorter wall
Keyboard: ← → step, Space play or pause. 2 to 12 heights, whole numbers from 0 to 30. With the real limits (n ≤ 100,000, heights ≤ 10,000) the largest area is under 10⁹, so a 32-bit int is enough in Java and C++.