DSAVisualiseData Structures & Algorithms Studio
Intervals & Sweep Lines Medium

Interval Scheduling: Minimum Rooms

TrainingSessions turns each half-open interval into a start and end event, sorts the events, and sweeps once to find peak overlap.

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) events

Array state

Follow the active comparisons and writes.

Live snapshot

Current operation

Trace state
Ready to explore
Source behavior & common mistakes

Follow stable session and event identities through event creation and the sweep. End events sort before starts at the same timestamp, so sessions that touch do not overlap.

  • Sessions include their start and exclude their end.
  • At equal timestamps, the source sorts -1 end events before +1 start events.
  • The maximum is checked after applying each event delta.
  • The source comparator subtracts int timestamps, so widely separated signed extremes can overflow and sort incorrectly.
  • A zero-length interval contributes an end before its start and does not increase the reported maximum.

Algorithm code

Java
TrainingSessions.java (pinned repository source)Step linked
The highlighted line follows the current step.

Ready to begin

Press Play to see what happens.

Detailed execution
Snapshot 1 / 1