← switch

11. Container With Most Water

medium

Array · Two Pointers · Greedy

read the problem on leetcode →

first solved 15 Sept 2026

python
class Solution:
    def maxArea(self, height: List[int]) -> int:
        left = 0
        right = len(height) - 1
        max_area = 0

        while left < right:
            width = right - left
            current_height = min(height[left], height[right])

            max_area = max(max_area, width * current_height)

            if height[left] < height[right]:
                left += 1
            else:
                right -= 1

        return max_area