Construct Canonical Skyline Height-Change Points

Quick Overview

Construct canonical skyline key points by grouping equal-x building events and tracking active height multiplicities.

Construct Canonical Skyline Height-Change Points

Company: Microsoft

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Other

### Problem Return the skyline formed by rectangular buildings resting at height zero. A building is `[left,right,height]`. Represent the upper contour as key points `[x,height]` sorted by x, including zero-height ground gaps and a final height-zero point at the rightmost building end. Emit a point only when the skyline height changes; consecutive horizontal segments of equal height must be merged. ```cpp vector<vector<int>> getSkyline(vector<vector<int>>& buildings); ``` ### Examples ```text Input: buildings = [[1,4,3],[2,6,5],[6,8,5],[9,10,2]] Output: [[1,3],[2,5],[8,0],[9,2],[10,0]] ``` The equal-height buildings meeting at x=6 make one continuous height-5 segment. ```text Input: buildings = [[0,3,4],[1,2,2]] Output: [[0,4],[3,0]] ``` ### Constraints - There are between 1 and 10000 buildings, sorted by nondecreasing left edge. - `0 <= left < right <= 2147483647`. - Heights lie between 1 and 2147483647. - Output key points describe the contour, not individual building edges hidden below it.

Overview: Construct canonical skyline key points by grouping equal-x building events and tracking active height multiplicities.

Microsoft logo
Microsoft
Sep 30, 2026
hardSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Return the skyline formed by rectangular buildings resting at height zero. A building is [left,right,height]. Represent the upper contour as key points [x,height] sorted by x, including zero-height ground gaps and a final height-zero point at the rightmost building end. Emit a point only when the skyline height changes; consecutive horizontal segments of equal height must be merged.

vector<vector<int>> getSkyline(vector<vector<int>>& buildings);

Examples

Input: buildings = [[1,4,3],[2,6,5],[6,8,5],[9,10,2]]
Output: [[1,3],[2,5],[8,0],[9,2],[10,0]]

The equal-height buildings meeting at x=6 make one continuous height-5 segment.

Input: buildings = [[0,3,4],[1,2,2]]
Output: [[0,4],[3,0]]

Constraints

  • There are between 1 and 10000 buildings, sorted by nondecreasing left edge.
  • 0 <= left < right <= 2147483647 .
  • Heights lie between 1 and 2147483647.
  • Output key points describe the contour, not individual building edges hidden below it.