The Skyline Problem

Asked atMicrosoftZomatoSalesforce
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below
0
Stuck? Show a way to structure it+
  1. 01Sort building start events by x and sweep from left to right.
  2. 02Maintain active buildings in a max-heap keyed by height with their right endpoints.
  3. 03At each x, add all starts, remove expired buildings, and emit a point only if the maximum height changes.
  4. 04Process every event sharing an x-coordinate before emitting a key point.

Reference answer

Then expect these follow-ups

  • How should start and end events at the same x be ordered?

    Tests: event ties

  • How would a divide-and-conquer skyline solution work?

    Tests: alternative algorithm

Free to read · better with Enzo

Practice this out loud with Enzo

Enzo runs it as a mock interview, pushes back with follow-ups, and grades you on the rubric.

Next question