The Skyline Problem
Try to solve The Skyline problem.
We'll cover the following
Statement
Imagine standing at a distance, viewing the skyline of a city. The skyline is the shape formed by all the buildings in the city when viewed together. Your task is to determine the shape of this skyline, given all the buildings’ position and height. Each building is represented by three values in the array buildings
, where
left
i
is the-coordinate where the building starts. right
i
is the-coordinate where the building ends. height
i
is the height of thebuilding.
All buildings are rectangles that sit on flat ground (height
Note: The output skyline should not have multiple horizontal lines at the same height in a row. For example, an output like
is incorrect. The three lines with height should be combined into one, so the correct version would be .
Constraints:
buildings.length
left
i
right
i
height
i
buildings
is sorted byleft
i
in ascending order.
Examples
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.