A city block contains n buildings. Building i is a rectangle standing on the ground: it spans horizontally from left to right (left < right) and has height height. Looking at the block from far away, the buildings form a silhouette (the skyline). A key point is a position where the silhouette's height changes as you scan from left to right; the standard skyline is the minimal list of such points, and it always ends with the point where the silhouette drops back to height 0 on the far right. Report the number of key points in this minimal skyline.
Line 1: an integer n.
Next n lines: three integers left, right, height describing one building.
A single integer: the number of key points in the skyline.
Example 1
Input
1 2 9 10
Expected
2
Explanation
One building yields the skyline (2,10) then (9,0): 2 key points.
Example 2
Input
2 1 5 3 2 7 4
Expected
3
Explanation
The silhouette rises to 3 at x=1, to 4 at x=2, and drops to 0 at x=7: key points (1,3),(2,4),(7,0), so 3.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →