← All questions
HardCoding
The Skyline Problem
Asked at
Microsoft
Zomato
Salesforce
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+
- 01Sort building start events by x and sweep from left to right.
- 02Maintain active buildings in a max-heap keyed by height with their right endpoints.
- 03At each x, add all starts, remove expired buildings, and emit a point only if the maximum height changes.
- 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