Compute the Skyline Outline of a Fulfillment Center Campus
Last updated: November 29, 2026
Quick Overview
Given rectangular buildings on a flat campus as [left, right, height], return the skyline as a list of key points [x, height] where the outline height changes, ordered by x, with no consecutive points of equal height.
Amazon
November 29, 20260
0
0 solved
Given rectangular buildings on a flat campus as [left, right, height], return the skyline as a list of key points [x, height] where the outline height changes, ordered by x, with no consecutive points of equal height.
An Amazon onsite hard sweep-line problem, here framed as generating a campus silhouette for a site-planning map. The interviewer looks for event sorting, a max-heap of active heights with lazy deletion, and careful tie handling so no redundant key points appear.
What the Interviewer Expects
- Generate start events and process buildings by left edge
- Maintain a max-heap of (height, right) for active buildings
- Lazily pop buildings whose right edge has passed
- Emit a key point only when the max height changes
- Handle ties at the same x correctly
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 it with divide and conquer by merging two skylines.
- Compute the total visible silhouette area instead.
- How would you update the skyline when one building is added?
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, list of [left, right, height] with left < right and height > 0, sorted by left. Output: list of [x, h] key points; the last point always has height 0....
High-Level Design
Sweep over every distinct x where a building starts or ends. At each x:
- Push every building with
left == xonto a max-heap as(-height, right). - Pop tops whose
right <= x; they no longer c...