Employee Free Time

IF
AlgoAxiomStaff Engineers
JSTS
Hard20 mins

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, positive-length free time for all employees, also in sorted order.

Examples

Example 1:

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

Output: [[3,4]]

Explanation: There are a total of three employees, and all common free time intervals would be [3,4].

Example 2:

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

Output: [[5,6],[7,9]]

Explanation: There are a total of three employees. The common free time intervals are [5,6] and [7,9].

Example 3:

Input: schedule = [[[1,2],[3,4]],[[2,3]]]

Output: []

Explanation: After merging all intervals we get [1,4] with no gaps, so there is no common free time.

Constraints

  • 1 <= schedule.length <= 50
  • 1 <= schedule[i].length <= 50
  • 0 <= schedule[i][j][0] < schedule[i][j][1] <= 10^8
  • Each employee's intervals are non-overlapping and sorted by start time
Source: Intervals pattern — AlgoAxiom
JavaScript
Test Case 1
root = [1, 2, 3]
Test Case 2
root = [1, 2, 3, 4, 5]
Idle