My first instinct was to merge all the busy intervals into one big union and then just look at the gaps.
First, determine the global time window by finding the minimum start and maximum end across all busy intervals. Then, merge all busy intervals from all people into a single list of non-overlapping intervals, and finally compute the free intervals within the global window by taking the gaps between merged busy intervals. Alternatively, use a sweep-line approach with events to track the number of busy people at any time.
Pro tip: Clarify edge cases upfront, such as empty schedules or no common free time, and discuss how to handle them. Also, mention that the solution can be optimized to O(N log N) where N is total number of intervals, and that using a heap for merging might be more efficient if schedules are large.
Ask questions to confirm details: Are intervals inclusive? What if someone has no busy intervals? Should the output be sorted? What is the expected input size? This ensures you understand the requirements and can tailor your solution.
Iterate through all schedules to find the earliest start time and the latest end time among all busy intervals. This defines the range within which we need to find free slots.
Collect all busy intervals from all people into a single list, sort them by start time, and merge overlapping intervals. This gives a consolidated view of when at least one person is busy.
Within the global window, identify the gaps between the merged busy intervals. These gaps represent times when everyone is free. Handle the boundaries: if the first busy interval starts after the global start, there is a free slot from global start to that start; similarly for the end.
State the time complexity: O(N log N) due to sorting, where N is total number of intervals. Mention that if schedules are already sorted, a k-way merge using a heap can achieve O(N log k) where k is number of people. Also, discuss space complexity.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.