Loading...
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.
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.
Input: height = [1,1]
Output: 1
height.length ≤105height[i] ≤104Click "Run" to test with sample cases or "Submit" to run all tests.