Imagine you're standing far away from a city, looking at its magnificent skyline. What you see is the outer contour - a silhouette formed by all the buildings against the horizon.
Given an array buildings where each building is represented as [left, right, height], your task is to return the key points that define this skyline.
What makes a key point?
- It's where the skyline height changes
- It's the left endpoint of each horizontal segment
- No consecutive points should have the same height
The result should be a list of coordinates [[x1,y1], [x2,y2], ...] sorted by x-coordinate, ending with a point at height 0 where the rightmost building ends.
Example: Buildings [[2,9,10], [3,7,15], [5,12,12]] create a skyline with key points [[2,10], [3,15], [7,12], [12,0]]
Input & Output
Constraints
- 1 โค buildings.length โค 104
- 0 โค lefti < righti โค 231 - 1
- 1 โค heighti โค 231 - 1
- Buildings are given as [left, right, height] where left < right