Skyline contour

Write codeHard40 minGoogle style

Your task

Given a list of buildings, each as [left, right, height] (right > left, height > 0), compute the skyline as a list of key points [x, height] where the height changes, sorted by x. The skyline is the outer contour formed by the silhouette of all buildings; the last key point always has height 0 (ground after the rightmost building). Buildings may overlap. There are up to 10^4 buildings; coordinates and heights fit in 32-bit ints.

Examples

skyline(buildings: list[list[int]]) -> list[list[int]]
Example 1
Inputskyline([[2, 9, 10], [3, 7, 15], [5, 12, 12], [15, 20, 10], [19, 24, 8]])
Output[[2, 10], [3, 15], [7, 12], [12, 0], [15, 10], [20, 8], [24, 0]]