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 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) events
Array state
Follow the active comparisons and writes.
Current operation
Trace stateReady 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
JavaTrainingSessions.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