Common Free Slot Across Calendars
Each teammate's calendar is a list of busy intervals, already sorted and non-overlapping per person. To schedule a group sync, find every positive-length window during which all teammates are simultaneously free.
Problem
Given the busy schedules of several people (each a sorted list of non-overlapping [start, end] intervals), return the finite list of common free intervals shared by everyone, sorted by start. Exclude the unbounded gaps before the first and after the last busy interval.
Input
A list of schedules; each schedule is a list of [start, end] integer intervals.
Output
A sorted list of [start, end] free intervals common to all (each with start < end).
Constraints
- 1 ≤ total intervals ≤ 5·10^4
- Per person, intervals are sorted and disjoint
- Only finite gaps between busy periods are returned
Examples
Example 1
Input
schedule = [[[1,2],[5,6]],[[1,3]],[[4,10]]]
Output
[[3,4]]
The only window everyone is free is from 3 to 4.
Example 2
Input
schedule = [[[1,3],[6,7]],[[2,4]],[[2,5],[9,12]]]
Output
[[5,6],[7,9]]
Merging all busy times leaves free gaps [5,6] and [7,9].