Draw the Skyline Outline of Buildings for a 3D Map Layer
Last updated: November 29, 2026
Quick Overview
Each building is (left, right, height) on a flat line. Return the skyline as a list of key points (x, h) where the outline height changes, sorted by x, with no consecutive equal heights.
0
0
0 solved
Each building is (left, right, height) on a flat line. Return the skyline as a list of key points (x, h) where the outline height changes, sorted by x, with no consecutive equal heights.
A classic Google onsite hard problem, natural for the Maps 3D buildings layer. The interviewer checks a sweep over edges with a max-heap of active heights and lazy removal of buildings that have ended.
What the Interviewer Expects
- Sweeps x coordinates in order
- Keeps a max-heap of (height, right) for active buildings
- Lazily removes buildings whose right edge has passed
- Emits a point only when the max height changes
- States O(n log n)
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Solve with divide and conquer merging
- Return total visible area
- Handle buildings on a 2D plane (much harder)
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: buildings
(left, right, height)with left < right, height > 0. - Output: points
[x, h]where h is the new outline height starting at x; last point has h = 0. - No two consecutive points s...
High-Level Design
The outline height at x is the tallest building covering x. Collect every distinct x where a building starts or ends. Sweep them in order, keeping a max-heap of (-height, right) for buildings that h...