mediumIntervalsAmazon
Lecture Hall Pruner
An admin removes the FEWEST sessions from a conflict-ridden schedule so that the remainder is conflict-free.
Given intervals, return the minimum number of intervals to remove so no two overlap.
Choose approach
1/5
Narrationstep 1 of 5
Keep I0; running end = 2.
Variables
i=0
end=2
How to think about it
- Equivalent to maximum non-overlap set.
- Sorting by end > sorting by start for this task.
Edge cases to catch in interview
- All overlap -> keep 1, remove n-1.
- All disjoint -> 0 removals.
Examples
Example 1
2{"intervals":[[1,2],[1,2],[1,2]]}
Try your own input
SpacePlay / pause
← / →Previous / next step
RReset to start
. or >Cycle speed