class Solution:
    def maxArea(self, height: List[int]) -> int:
        # time O(N) space O(1)
        """
        main idea: two pointers, change the pointer with shorter height 
        """
        l, r = 0, len(height)-1
        max_w = 0
        while l <r:
            h =min(height[l],height[r]) 
            max_w = max(max_w,h*(r-l))
            if height[l] <height[r]:
                l += 1
            else:
                r -= 1
        return max_w

optimized version

class Solution:
    def maxArea(self, height: List[int]) -> int:
        # time O(N) space O(1)
        """
        main idea: two pointers, change the pointer with shorter height 
        """
        l,r = 0, len(height)-1
        wid = r -l
        water= 0 
        for w in range(wid,0,-1):
            if height[l] < height[r]:
                water, l = max(water,height[l]*w),l+1
            else:
                water, r = max(water,height[r]*w),r-1
        return water