10. 11. Container With Most Water
Last updated
Last updated
Input: height = [1,8,6,2,5,4,8,3,7]
Output: 49
Explanation: The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49.Input: height = [1,1]
Output: 1/**
* @param {number[]} height
* @return {number}
*/
var maxArea = function (height) {
let max = 0;
let l = 0;
let r = height.length - 1;
while (l < r) {
const h = Math.min(height[l], height[r]);
const c = h * (r - l);
if (max < c) max = c;
if (height[l] === h) l++; else r--;
}
return max;
};