Skip to content

Instantly share code, notes, and snippets.

@amarjitdhillon
Last active February 7, 2022 05:55
Show Gist options
  • Save amarjitdhillon/ecf0a48c05fa3499653ef3c4f921b72f to your computer and use it in GitHub Desktop.
Save amarjitdhillon/ecf0a48c05fa3499653ef3c4f921b72f to your computer and use it in GitHub Desktop.
Container With Most Water
class Solution:
def maxArea(self, height: List[int]) -> int:
maxArea, currArea, l, r = 0,0, 0, len(height)-1
while(l < r and l >= 0 and r <= len(height)-1):
currArea = min(height[l],height[r]) * (r-l)
if currArea > maxArea:
maxArea = currArea # udpate the max area
if height[l] < height[r]: # left pointer needs to be incremented
l += 1
else: # both cases of height[l] > height[r] and height[l] == height[r]
r -= 1
return maxArea
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment