11. Container With Most Water
Solution:
- two pointers left and right. move the smaller of the two towards the middle.
- the area is calculated each loop
- the solution itself is actually very simple but it takes time in understanding how this solution works.
class Solution:
def maxArea(self, height: List[int]) -> int:
maximum = 0
l = 0
r = len(height) - 1
while l < r:
area = (r - l) * min(height[l], height[r])
if area > maximum:
maximum = area
print(area, l, r, height[l+1], height[r-1])
if height[l] < height[r]:
l += 1
else:
r -= 1
return maximum