DSAVisualiseData Structures & Algorithms Studio
Intervals & Sweep Lines Hard

Building Skyline (Sweep Line)

A sweep line tracks the tallest active building as start and end events pass from left to right.

Trace input

Bounded JSON

Edit the lesson input, then build a deterministic source-linked trace.

This lesson validates its own input and operation limits.

Source scenarios

Complexity

BestO(N log N)
AverageO(N log N)
WorstO(N log N)
SpaceO(N)

Array state

Follow the active comparisons and writes.

Live snapshot

Current operation

Trace state
Ready to explore
Source behavior & common mistakes

Return key points only where the visible maximum height changes; the source treats each right endpoint as inclusive.

  • Emitting one point for every event instead of only height changes.
  • Processing equal-x events one at a time.
  • Ending a building at its right coordinate instead of right + 1.

Algorithm code

Java
Skyline.javaStep linked
The highlighted line follows the current step.

Ready to begin

Press Play to see what happens.

Detailed execution
Snapshot 1 / 1