Skip to content

Instantly share code, notes, and snippets.

@TheDudeWithTheThing
Last active December 5, 2016 16:03
Show Gist options
  • Save TheDudeWithTheThing/75ade344782cc998f2726fb561c6482b to your computer and use it in GitHub Desktop.
Save TheDudeWithTheThing/75ade344782cc998f2726fb561c6482b to your computer and use it in GitHub Desktop.
My SkyLine solution
class SkySkraper
def self.area(coords)
area_total = 0
height_at = {}
coords.each do |set|
(x1, x2, height) = set
range_exclude_last(x1, x2).each do |x|
height_at[x] ||= 0
if height > height_at[x]
area_total += height - height_at[x]
height_at[x] = height
end
end
end
area_total
end
def self.range_exclude_last(x1, x2)
(x1..x2 - 1).to_a
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment