Skip to content
BytePatterns

Employee Free Time

HardIntervals#intervals#merge~40m

Problem

Each employee has a list of busy intervals, already sorted and non-overlapping within that employee. Return the positive-length stretches of time during which every employee is free, in order. A stretch before the first busy interval or after the last one does not count — only gaps between busy time.

Examples

Input:  schedules = [[[1, 2], [5, 6]], [[1, 3]], [[4, 10]]]
Output: [[3, 4]]
Why:    after 3 nobody is busy until 4, and from 4 onwards the third employee is
Input:  schedules = [[[1, 3], [6, 7]], [[2, 4]], [[2, 5], [9, 12]]]
Output: [[5, 6], [7, 9]]
Why:    busy time runs 1-5, then 6-7, then 9-12
Input:  schedules = [[[1, 2]], [[1, 2]]]
Output: []
Why:    edge case, the busy time is one solid block with no gap inside it

Hints

0 / 3

Stuck on the idea rather than the code? Merge Intervals covers it.