A team's working hours are given as schedule, where schedule[i] is the list of times employee i is busy. Each busy time is an Interval with a start and an end, written here as [start, end]; the employee is busy from start up to end.
Return every stretch of time when all the employees are free at once, as a list of intervals sorted by start. Only count stretches that are:
[1,3] and [3,5]), there is no free time between them.Within each employee's own list, the intervals are already sorted, and none of them overlap. The intervals of different employees can overlap freely.
Taken together, someone is busy from 2 to 5, from 7 to 8 and from 9 to 12. The gaps between those, 5 to 7 and 8 to 9, are when everyone is free.
The first two employees keep someone busy from 0 all the way to 9: the second employee's [2,8] covers the first employee's break from 6 to 8. The only shared free time is from 9 until the third employee starts at 10.
[]
The busy times run 1 to 5, then 5 to 6, then 6 to 9, each one starting exactly when the previous one ends. Those gaps have zero length, so there is no free time.
Constraints
1 <= schedule.length <= 501 <= schedule[i].length <= 500 <= schedule[i][j].start < schedule[i][j].end <= 10⁸schedule[i] is sorted by start, and each interval in it starts no earlier than the one before it ends.Free time for everyone is time that no employee's interval covers. Who owns an interval doesn't matter: put them all together and sort them by start time.
[[[2,4],[9,12]],[[3,5]],[[7,8]]]