City Skyline Outline Problem
City Skyline Outline Problem — ExecCode Hard DSA Practice
Solve the City Skyline Outline problem on ExecCode. Free online hard DSA practice in Stacks & Queues. Write and run code in Java, C++, Python — no signup required to run.
Problem description
A skyline is the outline formed if you look at a city of axis-aligned rectangular buildings from far away. Overlapping buildings hide each other; only the tallest contour at each x-coordinate is visible. Each building is [left, right, height) — occupied on [left, right) at that height. Return the key contour points [x, height] from left to right where the visible height changes. The last point drops to height 0 after the rightmost building. You are given: buildings — list of [left, right, height] with left 0 Return a list of [x, height] points in increasing x. No two consecutive points share the same height. If two buildings share an edge, the height should not stutter with a fake zero in between.
Examples
Input {'buildings': [[2, 9, 10], [3, 7, 15], [5, 12, 12], [15, 20, 10], [19, 24, 8]]}; Output [[2, 10], [3, 15], [7, 12], [12, 0], [15, 10], [20, 8], [24, 0]]. Input {'buildings': [[0, 2, 3], [2, 5, 3]]}; Output [[0, 3], [5, 0]]. Input {'buildings': [[1, 2, 1], [1, 2, 2], [1, 2, 3]]}; Output [[1, 3], [2, 0]]
Constraints
Coordinates are non-negative integers
Practice City Skyline Outline free on ExecCode. Browse DSA problems, topic map, and placement guides.