Facebook Pixel

Skyline problem

You are given a list of buildings. Each building is a rectangle described by [Li, Ri, Hi], where Li is the left x-coordinate, Ri is the right x-coordinate, and Hi is the height. All buildings stand on height 0.

Your task is to return the skyline formed by all buildings together.

A skyline is represented by key points [[x1, y1], [x2, y2], ...]. Each key point marks where the skyline height changes. The last key point always ends at height 0.

For example, for buildings [[2, 9, 10], [3, 7, 15], [5, 12, 12], [15, 20, 10], [19, 24, 8]], the skyline is [[2, 10], [3, 15], [7, 12], [12, 0], [15, 10], [20, 8], [24, 0]].

Examples

Example 1:

Input: [[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]]

Try it yourself

Invest in Yourself
Your new job is waiting. 83% of people that complete the program get a job offer. Unlock unlimited access to all content and features.
Go Pro