Iterate through the entire heights array and compute the area for each possibility - O(n2)
you’ll notice that if we start at opposite ends, that is the largest length we can get
the largest height is also bottlenecked by the smaller height
Optimal 2 Pointer Approach
Start at opposite ends
Calculate the height
Change the pointer of the bottlenecking height, ensure we are keeping the larger height
classSolution:defmaxArea(self, height: List[int])->int: l, r =0,len(height)-1 maxArea =0while l < r:# compute the height area =min(height[l], height[r])*(r-l) maxArea =max(maxArea, area)# inc/dec the bottleneckif height[l]< height[r]: l +=1else: r -=1return maxArea