Skip to content

Instantly share code, notes, and snippets.

@mlivingston40
Last active March 28, 2024 17:00
Show Gist options
  • Save mlivingston40/cf55070847fd57259c182014b8a4fb5c to your computer and use it in GitHub Desktop.
Save mlivingston40/cf55070847fd57259c182014b8a4fb5c to your computer and use it in GitHub Desktop.
Container with most water
class Solution:
def __init__(self):
self.max_area = 0
def getLength(self, index_left, index_right) -> int:
return index_right - index_left
def maxArea(self, height: List[int]) -> int:
e_index = 0
for e in height:
e_right_index = e_index+1
# e is left height
left_height = e
while e_right_index < len(height):
right_height = height[e_right_index]
min_height = min([left_height, right_height])
# now need to find the length of the rectangle
length = self.getLength(e_index, e_right_index)
# area of this rectangle to evaluate
eval_max_area = min_height*length
print([left_height, right_height])
print(eval_max_area)
print("****")
if eval_max_area > self.max_area:
self.max_area = eval_max_area
# move e_right_index up one
e_right_index += 1
# move the left index pointer up
e_index += 1
return self.max_area
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment