Container With Most Water 0(n) LeetCode#11

function maxAreaOfWater(heights){
let maxArea=0;
let left = 0;
let right = heights.length -1;
while(left < right){
maxArea = Math.max(maxArea, Math.min(height[left], height[right])* (right - left )); if(height[left] < height[right]){
left++;
}else{
right--;
}
}
return maxArea;
}
— Rumi

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store