Objective
Each number is the height of a wall. Two walls form a container of area distance × smaller height. With two pointers from the ends, always moving the one on the lower wall finds the maximum in O(n).
Instructions
- Read a line with the heights (non-negative integers, at least two).
- Show
Maximum area: xwith the largest possible area.
1 8 6 2 5 4 8 3 7
Maximum area: 49
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise