FAANG · LeetCode #218
The Skyline Problem — three-stage drill
1The ProblemHard
The Skyline Problem
Trace the silhouette of a city of overlapping buildings — return the key (x, height) points where the outline changes.
Examples
[[2,9,10],[3,7,15],[5,12,12]]→ [[2,10],[3,15],[7,12],[12,0]][[0,2,3],[2,5,3]]→ [[0,3],[5,0]]
constraintOutput is a list of [x, h] key points marking where the silhouette height changes. The last point has height 0.
2The PatternTIME O(n log n) · SPACE O(n)
Intervals
Given a pile of ranges, sort them by start — now any overlap is a neighbour, so a single left→right pass handles them.
Problems using this pattern
3The SolutionRESULT → [[2,10],[3,15],[7,12],[12,0]]
Step through it
given: 3 buildings · trace the silhouette (skyline)
Step 1 / 8
Arrow keys to navigate · escape to reset