Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save codertcet111/69e738ce4eb031b73c3778b241cb30ab to your computer and use it in GitHub Desktop.
Save codertcet111/69e738ce4eb031b73c3778b241cb30ab to your computer and use it in GitHub Desktop.
Leetcode 11: Container with most water storage
Leetcode 11: Container with most water storage
# @param {Integer[]} height
# @return {Integer}
def max_area(height)
i = 0
j = height.length - 1
max_r = 0
while i < j do
if height[i] < height[j]
curr = height[i] * (j - i)
max_r = [max_r, curr].max
k = i + 1
while k < j && height[k] < height[i] do
k += 1
end
i = k
else
curr = height[j] * (j - i)
max_r = [max_r, curr].max
k = j - 1
while k > i && height[k] < height[j] do
k -= 1
end
j = k
end
end
max_r
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment