summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--2020/11/30/main.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/2020/11/30/main.rb b/2020/11/30/main.rb
new file mode 100644
index 0000000..2d03e38
--- /dev/null
+++ b/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]]