Medium Problems

11. Container With Most Water

Solutions

function maxArea(height: number[]): number {
let maxarea = 0;
for(let left = 0; left < height.length; left++) {
  for(let right = left + 1; right < height.length; right++) {
      let width = right - left;
      maxarea = Math.max(maxarea, Math.min(height[left], height[right]) * width)
  }
}
return maxarea;
};

Video Solution

...my first thought with this is, what's the brute force way, what's the easiest way to solve this problem. Well, let's just try every single combination of left and right, let's just try every single possible container we could made...

Last Update: 11:43 - 16 April 2024
Array
Two Pointers
Greedy

On this page