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 JSONEdit the lesson input, then build a deterministic source-linked trace.
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.
Current operation
Trace stateReady 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
JavaSkyline.javaStep linked
The highlighted line follows the current step.
Ready to begin
Press Play to see what happens.
Detailed execution
Snapshot 1 / 1