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

Hiring now

Salesforce has 1,420 open roles right now

Also hiring: Zomato

landed applies to roles like these for you, on each company’s own site, with answers written for the role.

Get 5x interviews10 free auto-applies. No card.
  • Software Engineering MTS

    India - Hyderabad

  • Senior Software Engineer, Data Ingestion

    Georgia - Atlanta

  • Software Engineering AMTS (College Grad)

    California - San Francisco

Or practice this question first

Next question