Created
January 23, 2020 22:36
-
-
Save muxcmux/c3dec816b341a3e813b2f708a99bb459 to your computer and use it in GitHub Desktop.
this is think is O(n2)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @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