Clear the Talk Schedule
Medium · Greedy & Intervals · about 20 min
A conference has one stage. Each talk is [start, end] with start < end. Two talks clash if they overlap in time, but a talk that ends at minute 10 and one that starts at minute 10 do not clash.
Return the smallest number of talks to cancel so that no two remaining talks clash.
- 0 to 10^5 talks, in any order. Times may be negative.
fewest_cancellations([[1, 4], [2, 3], [3, 6], [5, 7]]) → 2 (keep [2, 3] and [3, 6])
Hints
- Think about which talks to keep rather than which to cancel.
- Among the talks that could come next, the one that ends earliest leaves the most room.
- Sort by end time and keep a talk if it starts at or after the end of the last kept talk.
Learn the pattern first: the Greedy & Intervals lesson.
More Greedy & Intervals problems
- Stepping Stones Across the Creek (Easy)
- Artist Blocks in a Playlist (Easy)
- Squeeze In a Booking (Medium)
- Electric Bus Loop (Medium)
- Team Bonus Tokens (Hard)
- Road Trip Fuel Stops (Hard)