Skyline Problem In Java.
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 height of all the buildings as shown on a cityscape below. Write a program to output the skyline formed by these buildings collectively.
Lets simplify the problem statement and understand it correctly,
If there are many buildings in a area as shown in below picture, If same buildings is viewed from distance then what we can see is not all the buildings but the skyline that is borders of all buildings.
You can see skyline of buildings if viewed from a side and remove all sections that are not visible/overlapped.
All buildings have common base and every building is represented by 3 points(left, right, height)
‘left': is x coordinate of building left wall.
‘right': is x coordinate of building right wall
‘height': is height of building. A skyline is a collection of rectangular strips. A rectangular strip is represented as a pair (left, height) where left is x coordinate of building left wall and height is height of building.
Lets understand what is the input and the expected output.
INPUT:
You are given a building coordinates as shown below,
int[][] skyscraper = { {2,9,10}, {3,6,15}, {5,12,12}, {13,16,10}, {15,17,5} };
OUTPUT:
Skyline Coordinates = { {2,10}, {3,15}, {6,12}, {12,0}, {13,10}, {16,5}, {17,0} }