Quant Memo
Coding/●●●●

Container with the most water

Given non-negative heights, each a vertical line at unit spacing, pick two of them so that the container formed with the x-axis holds the most water. The volume between lines l and r is min(height[l], height[r]) * (r - l).

height = [1,8,6,2,5,4,8,3,7]  ->  49

Return the maximum water a container can hold. Aim for O(n)O(n) time and O(1)O(1) space.

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions