A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance.
Now suppose you are given the locations and heights of all the buildings, write a program to output the skyline formed by these buildings collectively. Location of building is specified using tuple [x1,x2,h] where 'x1' is starting point of a building, 'x2' is where building ends and 'h' is height of the building. The skyline would be returned as a set of key points.
Starting point of each horizontal line segment of the skyline is marked as a key point. Complete skyline therefore could be specified using set of such key points.
For example, if input is an array of building co-ordinates: [[2,9,10], [13,15,10]] then the output should be the skyline specified as [[2,10],[9,0],[13,10],[15,0]]. In the below diagram, input buildings are shown on the left hand side and the output is shown on the right hand side with highlighted key points.
If input is [[2,9,10], [3,6,15], [5,12,12], [13,16,10], [13,16,10], [15,17,5]] then the output should be [[2,10], [3,15], [6,12], [12,0], [13,10], [16,5], [17,0]] as shown below.