You are given an integer array height of length n. At each position i stands a vertical line from (i, 0) up to (i, height[i]).
Pick two of these lines. Together with the x-axis they form a container, and the water it can hold is the distance between the two lines multiplied by the height of the shorter one (the container cannot be slanted).
Return the maximum amount of water any such container can hold: the maximum of (j - i) * min(height[i], height[j]) over all pairs i < j.
Examples
Example 1
Input: height = [1,8,6,2,5,4,8,3,7]
Output: 49
Explanation: The lines at indices 1 and 8 have heights 8 and 7. They are 7
apart, and the shorter is 7, so the container holds 7 * 7 = 49, the maximum.
Example 2
Input: height = [1,1]
Output: 1
Constraints
2≤height.length≤105
0≤height[i]≤104
Loading editor...
Log in to run your code. Your draft is saved in this browser.Log inSign up