Skip to content

Instantly share code, notes, and snippets.

@muxcmux
Created January 23, 2020 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muxcmux/c3dec816b341a3e813b2f708a99bb459 to your computer and use it in GitHub Desktop.
Save muxcmux/c3dec816b341a3e813b2f708a99bb459 to your computer and use it in GitHub Desktop.
this is think is O(n2)
# @param {Integer[]} height
# @return {Integer}
def max_area(heights)
max = 0
heights.each_with_index do |y, x|
heights.each_with_index do |y1, x1|
width = (x - x1).abs
area = [y, y1].min * width
max = area if area >= max
end
end
max
end
example = [1,8,6,2,5,4,8,3,7]
puts max_area(example)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment