← Google Interview Insights

Google·Software Engineer·Onsite - Coding / Algorithms·Intermediate

IntermediatePrefer not to say
Apr 2026

Summary

Google SWE coding round, one question the whole time. The skyline problem. I'd seen it before but not practiced it enough to feel clean under pressure.

Questions Asked (1)

Q1

Given a list of rectangular buildings each defined by a left edge, right edge, and height, compute the skyline as a sorted list of key points where the visible height changes.

Algorithms & Data Structures
Author's notes

I knew this problem.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a sweep line algorithm with a max-heap to process building start and end events in sorted order, tracking the current maximum height. At each event, update the heap and record a key point if the maximum height changes.

Pro tip: Clarify edge cases upfront, such as adjacent buildings with the same height or zero-width buildings, and mention that the output should exclude redundant points where height doesn't change.

1. Understand the problem and define output

Confirm that the skyline is a list of (x, height) points where the height changes, and that buildings are axis-aligned rectangles. Discuss input format and constraints.

2. Choose an algorithm

Select a sweep line approach: create events for each building's left and right edges, sort them by x-coordinate, and use a max-heap to track active heights.

3. Process events and maintain active heights

Iterate through sorted events. For a left edge, push the height onto the heap; for a right edge, mark it as removed (lazy deletion). After each event, clean the heap top and compare the current max height to the previous one.

4. Record key points and handle edge cases

When the max height changes, append a key point (x, new height). Handle cases like multiple events at the same x, zero-height buildings, and ensure no duplicate points.

5. Analyze complexity and test

State time complexity O(n log n) due to sorting and heap operations, and space O(n). Walk through a small example to verify correctness.

Key Points to Mention

  • Sweep line algorithm with events for building start and end
  • Max-heap (priority queue) to track current maximum height
  • Lazy deletion to handle building ends efficiently
  • Sorting events by x-coordinate, with left edges before right edges at the same x
  • Time complexity O(n log n) and space O(n)
  • Edge cases: adjacent buildings, same heights, zero-width buildings, and output deduplication

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.