Container With Most Water

Problem Id: 11 Difficulty: Medium Tag: TBD


Intuition

Use two pointer to solve his problem.

Solution


class Solution:
    def maxArea(self, height: List[int]) -> int:
        max_water = 0
        lo, hi = 0, len(height) - 1
        while hi > lo:
            max_water = max(max_water, min(height[lo], height[hi]) * (hi - lo))
            if height[lo] > height[hi]:
                hi -= 1
            else:
                lo += 1
        return max_water