The Skyline Problem
Hard Intervals
buildings lists buildings standing on flat ground, each [left, right, height]: a rectangle from left to right along the ground, height tall. They come in no particular order, and may touch, overlap or stand inside one another.
The skyline is the outline they make together, seen from far away. At each point along the ground its height is the height of the tallest building standing there, where a building stands from its left up to but not including its right; where none stands, the outline is on the ground, at height 0.
Return the skyline's key points [x, height] from left to right: one at each x where the outline's height changes, giving its new height, the last one where it comes down to the ground. No two points in a row have the same height.
Example 1
The first building rises to 4 at 1. At 3 the second, 6 tall, rises above it and stands until 8, past the first one's end at 5, so the outline drops to the ground at 8. The third building stands alone from 10 to 12.
Example 2
Example 3
Constraints
1 ≤ buildings.length ≤ 5 × 10⁴buildings[i] = [left, right, height]0 ≤ left < right ≤ 10⁹1 ≤ height ≤ 10⁹
Solve it here
Write it in Python, Java or C++, run it on your own cases, and submit against hidden tests.
Practice this in an AI round
30 minutes on this problem with an AI agent beside your code, then a report on your solution and how you used the agent.
See the AI roundWatch the explanation
More Intervals
- Merge IntervalsAI round · Medium
- Insert IntervalAI round · Medium
- Non-overlapping IntervalsAI round · Medium
- Meeting Rooms IIMedium
- Interval List IntersectionsMedium