PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Google

Compute city skyline outline

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's understanding of interval processing and skyline/contour computation within computational geometry, focusing on reasoning about overlapping ranges and height aggregation.

  • hard
  • Google
  • Coding & Algorithms
  • Software Engineer

Compute city skyline outline

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

You are given a list of rectangular buildings in a 2D city skyline. Each building is represented by three integers `[L, R, H]`: - `L`: the x-coordinate of the left edge of the building, - `R`: the x-coordinate of the right edge of the building (`L < R`), - `H`: the height of the building. All buildings stand on a flat horizontal line (y = 0) and extend vertically up to height `H`. Buildings may overlap in the x-dimension. Your task is to compute the *skyline* formed by these buildings, as seen from a distance. The skyline should be represented as a list of **key points** `[x, height]` that describe the outer contour of the union of all buildings. A **key point** is a point where the height of the skyline changes. The output list must satisfy all of the following: 1. The list is sorted by increasing `x`. 2. No two consecutive points have the same height (i.e., the height must change at each key point). 3. The first point has a height greater than 0. 4. The last point has height 0, marking the end of the skyline. ### Input - An integer `n` — the number of buildings. - A list of `n` buildings, where each building is given as a triple `[L, R, H]` of integers. You may assume: - `1 <= n <= 10^4` - `0 <= L < R <= 10^9` - `1 <= H <= 10^9` ### Output Return a list of key points representing the skyline. Each key point is a pair `[x, height]` (or a 2-element array/tuple) of integers. ### Example Input: - `n = 3` - buildings = `[[2, 9, 10], [3, 7, 15], [5, 12, 12]]` One valid output: - `[[2, 10], [3, 15], [7, 12], [12, 0]]` Explanation (informal): - From x = 2 to 3, the highest building has height 10. - From x = 3 to 7, the highest building has height 15. - From x = 7 to 12, the remaining highest building has height 12. - After x = 12, there are no buildings, so the height drops to 0. Design an algorithm to compute the skyline key points for the given buildings.

Quick Answer: This question evaluates a candidate's understanding of interval processing and skyline/contour computation within computational geometry, focusing on reasoning about overlapping ranges and height aggregation.

Related Interview Questions

  • Solve Flower Placement and Directory Deletion - Google (medium)
  • Compute Turnstile Crossing Times - Google (hard)
  • Simulate In-Place Cellular State Updates - Google (hard)
  • Determine Whether a Word Exists in a Graph - Google (medium)
  • Implement Checksums and Feature Rollout Evaluation - Google (medium)
Google logo
Google
Dec 8, 2025, 7:36 PM
Software Engineer
Technical Screen
Coding & Algorithms
9
0

You are given a list of rectangular buildings in a 2D city skyline.

Each building is represented by three integers [L, R, H]:

  • L : the x-coordinate of the left edge of the building,
  • R : the x-coordinate of the right edge of the building ( L < R ),
  • H : the height of the building.

All buildings stand on a flat horizontal line (y = 0) and extend vertically up to height H. Buildings may overlap in the x-dimension.

Your task is to compute the skyline formed by these buildings, as seen from a distance. The skyline should be represented as a list of key points [x, height] that describe the outer contour of the union of all buildings.

A key point is a point where the height of the skyline changes. The output list must satisfy all of the following:

  1. The list is sorted by increasing x .
  2. No two consecutive points have the same height (i.e., the height must change at each key point).
  3. The first point has a height greater than 0.
  4. The last point has height 0, marking the end of the skyline.

Input

  • An integer n — the number of buildings.
  • A list of n buildings, where each building is given as a triple [L, R, H] of integers.

You may assume:

  • 1 <= n <= 10^4
  • 0 <= L < R <= 10^9
  • 1 <= H <= 10^9

Output

Return a list of key points representing the skyline. Each key point is a pair [x, height] (or a 2-element array/tuple) of integers.

Example

Input:

  • n = 3
  • buildings = [[2, 9, 10], [3, 7, 15], [5, 12, 12]]

One valid output:

  • [[2, 10], [3, 15], [7, 12], [12, 0]]

Explanation (informal):

  • From x = 2 to 3, the highest building has height 10.
  • From x = 3 to 7, the highest building has height 15.
  • From x = 7 to 12, the remaining highest building has height 12.
  • After x = 12, there are no buildings, so the height drops to 0.

Design an algorithm to compute the skyline key points for the given buildings.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Google•More Software Engineer•Google Software Engineer•Google Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.