Search⌘ K
AI Features

Solution: Employee Free Time

Explore how to identify overlapping employee working hours and compute shared free time intervals by merging sorted schedules. Understand the use of a min-heap to process intervals efficiently, detect gaps, and return combined free periods. This lesson helps you solve interval problems relevant to coding interviews.

Statement

You are given schedule, a list where each element contains the working hours of one employee.

Each employee’s working hours are represented as a list of Interval objects that are already sorted and do not overlap.

Return all finite intervals with non-zero duration during which all employees are simultaneously free. The resulting list of free intervals should also be sorted in ascending order.

Note: The intervals are represented as objects, not arrays. For example, schedule[1][1].start = 1 and schedule[1][1].end = 2, while schedule[0][0][0] is invalid. Do not include intervals with zero length (for example, [3, 3]) in the output.

Constraints:

  • 11 \leq schedule.length , schedule[i].length 50\leq 50

  • 00 \leq interval.start < interval.end 108\leq 10^8 ...