Intervals
Intervals: merging, inserting and intersecting ranges after sorting them by start, and counting the most that overlap at once.
Interval problems hand over items with a start and an end, bookings, shifts or charging sessions, and ask about overlap: which ones merge, where two lists agree, or how many run at once. Nearly all of them begin by sorting on the start, because once the intervals are in that order the next one can only overlap the last one already merged, and one pass replaces comparing every pair. The topic merges a list of numbers, then a day of room bookings derived from the repeat-until-stable brute force, and gives the merge template in three languages. It intersects two sorted lists with two pointers, counts the charging points a car park needs with a sweep of arrivals and departures, where whether touching intervals overlap becomes a decision, shows what sorting by end does to a merge, and ends with an exercise that inserts one booking into a sorted day.
Contents
8 cardsnot started