master
1def assert(x, y)
2 raise [x, y].inspect unless x == y
3end
4
5class Solution
6 def self.run(buildings)
7 changes = []
8 result = []
9 buildings.each do |building|
10 left, right, height = building
11 left.upto(right) do |n|
12 changes[n] = height
13 end
14 end
15 current = nil
16 changes.each_with_index do |item, index|
17 next if item == current
18
19 current = item
20 result << [index, item]
21 end
22 result << [changes.size, 0]
23 result
24 end
25end
26
27assert Solution.run([[2,8,3], [4,6,5]]), [[2,3], [4,5], [7,3], [9,0]]