DIY: Employee Free Time

Solve the interview question "Employee Free Time" in this lesson.

Problem statement

We are given a list containing the schedules of multiple people. Each person’s schedule is a list of non-overlapping intervals in sorted order. An interval is specified with the start time and an end time, both being positive integers. Your task is to find the list of intervals representing the free time for all the people. We are not interested in the interval from negative infinity to zero or from the end of the last scheduled interval in the input to positive infinity.

Constraints

  • 1 <= schedule.length , schedule[i].length <= 50
  • 0 <= schedule[i].start < schedule[i].end <= 10810^8
  • Every interval is guaranteed to have a non-zero duration.

Input

The input to the function is a two-dimensional array of integers. The following is an example input:

[[[2,3],[7,9]],[[1,4],[6,7]]]

Output

The following is the output of the above input:

[[4,6]]

Coding exercise

Implement the employeeFreeTime(schedule) function, where the schedule is a two-dimensional list of integers. It returns a list of Interval objects.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.