Skip to content

Employee Free Time

HardIntervals
Decode it first. Clues, constraints, pattern and plan before any code.

schedule[i] is the list of working intervals [start, end] for employee i, sorted and non-overlapping. Return the common free time: every stretch of positive length when no employee is working, between the first time anyone starts and the last time anyone finishes. Return the free intervals sorted.

schedule = [[[1, 2], [5, 6]], [[1, 3]], [[4, 10]]]
  →  [[3, 4]]
 
schedule = [[[1, 3], [6, 7]], [[2, 4]], [[2, 5], [9, 12]]]
  →  [[5, 6], [7, 9]]

Intervals that touch, like [1, 2] and [2, 3], leave no free time between them.

Constraints

  • 1 <= schedule.length, schedule[i].length <= 50
  • 0 <= start < end <= 10^8