bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 11. Container With Most Water

11. Container With Most Water

Leetcode Solutions

Two Pointer Approach

  1. Initialize two pointers, left at the start and right at the end of the array.
  2. Initialize maxarea to 0 to keep track of the maximum area found.
  3. While left is less than right: a. Calculate the current area as the product of the distance between the pointers and the height of the shorter line. b. Update maxarea if the current area is greater than the previously recorded maximum area. c. Move the pointer pointing to the shorter line towards the other end by one step. d. Repeat the process until left meets right.
  4. Return maxarea as the result.
UML Thumbnail

Brute Force Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...