Search⌘ K
AI Features

Solution: The Skyline Problem

Understand how to determine the outline of a city skyline by merging building segments using the union-find algorithm. Learn to process building coordinates, track maximum heights, and construct a skyline without redundant segments. This lesson teaches a practical approach to applying union-find to solve overlapping intervals efficiently.

Statement

Imagine standing at a distance, viewing the skyline of a city. The skyline is the shape formed by all the buildings in the city when viewed together. Your task is to determine the shape of this skyline, given all the buildings’ position and height. Each building is represented by three values in the array buildings, where buildings[i]=[lefti, righti, heighti]buildings[i] = [left_i,~right_i,~ height_i] ...