Commit ac4cbff
Changed files (1)
2020
11
30
2020/11/30/main.rb
@@ -0,0 +1,27 @@
+def assert(x, y)
+ raise [x, y].inspect unless x == y
+end
+
+class Solution
+ def self.run(buildings)
+ changes = []
+ result = []
+ buildings.each do |building|
+ left, right, height = building
+ left.upto(right) do |n|
+ changes[n] = height
+ end
+ end
+ current = nil
+ changes.each_with_index do |item, index|
+ next if item == current
+
+ current = item
+ result << [index, item]
+ end
+ result << [changes.size, 0]
+ result
+ end
+end
+
+assert Solution.run([[2,8,3], [4,6,5]]), [[2,3], [4,5], [7,3], [9,0]]