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
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

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
Sweep Line
Heap
Lazy Deletion
Geometry
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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:

  1. Push every building with left == x onto a max-heap as (-height, right).
  2. Pop tops whose right <= x; they no longer c...

Submit Your Answer
Markdown supported