VISUALGO//PROBLEMS
container with most water · two pointersmedium
LeetCode #11
height
1
8
6
2
5
4
8
3
7
current area
·
max area
0
ELEMENTS
height
Python
def maxArea(height: list[int]) -> int:
    left, right = 0, len(height) - 1
    max_area = 0

    while left < right:
        width = right - left
        h = min(height[left], height[right])
        max_area = max(max_area, width * h)

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

    return max_area