39/42
Part 8 of 8 · Follow-upsLearn and do

Many searches against the same calendars: build the runs once, then binary-search them

Build each person's or each listing's runs once, sorted. A search for the run that holds a day is then a binary search on the run starts. bisect_right(starts, day) - 1 gives the last run that starts at or before the day. That run holds the day if its end is at least the day.

Then reach and begins cost O(log r) for r runs, instead of a pass over the days.

In the editor, STARTS and ENDS are ana's runs, (1, 3) and (6, 7). Write run_holding(starts, ends, day): the run that holds day, found with one bisect_right.