AlgoLounge

Employee Free Time

hard

We are given a list schedule of employees, which represents the working time for each employee.

Each employee has a list of non-overlapping intervals, and these intervals are in sorted order.

Return the list of finite intervals representing the common free time for all employees, also in sorted order.

Even though we represent intervals as [a, b], the intervals within schedule are guaranteed to be non-overlapping for each individual employee.

Examples

Example 1

Input:  schedule = [[[1,2],[5,6]],[[1,3]],[[4,10]]]
Output: [[3,4]]

There are a total of three employees. All together, the combined working hours are [[1,3],[4,10]]. The free time would be [3,4].

Example 2

Input:  schedule = [[[1,3],[6,7]],[[2,4]],[[2,5],[9,12]]]
Output: [[5,6],[7,9]]

The combined working hours are [[1,5],[6,7],[9,12]]. The free time is [5,6] and [7,9].

Constraints

  • 1 <= schedule.length <= 50
  • 1 <= schedule[i].length <= 50
  • 0 <= schedule[i][j][0] < schedule[i][j][1] <= 10^8
TypeScript
Loading editor…
List of test cases (5)
Case 1
schedule = [[[1,2],[5,6]],[[1,3]],[[4,10]]]
Case 2
schedule = [[[1,3],[6,7]],[[2,4]],[[2,5],[9,12]]]
Case 3
schedule = [[[1,2]],[[3,4]],[[5,6]]]
Case 4
schedule = [[[1,10]],[[2,5]],[[3,7]]]
Case 5
schedule = [[[0,1],[4,5]],[[2,3]]]