heights[i] is the height of a vertical line at position i. Choose two lines that, together with the x-axis, form a container, and return the largest amount of water it can hold: min(height of the two lines) * distance between them. The container cannot be tilted.
For [1, 8, 6, 2, 5, 4, 8, 3, 7] the answer is 49.
The starter code tries every pair. It is correct but too slow for many lines.
Example 1
Input:
max_water([1, 8, 6, 2, 5, 4, 8, 3, 7])
Output:
49
Example 2
Input:
max_water([1, 1])
Output:
1
0 <= len(heights) <= 2000000 <= heights[i] <= 10**4No results yet
Run your code to check it against the examples, or submit to run every test.