Search⌘ K
AI Features

Employee Free Time

Explore how to determine overlapping free time intervals across multiple employee schedules. Learn to merge and evaluate interval objects efficiently to solve scheduling problems typical in 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, where interval is any interval in the list of schedules.

Examples

canvasAnimation-image
1 / 3

Understand the problem

Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:

Employee Free Time

1.

From the given list of employee schedules, find the list of intervals representing the free time for all the employees.

[[[3, 5], [8, 10]], [[4, 6], [9, 12]], [[5, 6], [8, 10]]]

A.

[[2, 8]]

B.

[[6, 8]]

C.

[[2, 6]]

D.

[[4, 6]]


1 / 3

Figure it out!

We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.

Sequence - Vertical
Drag and drop the cards to rearrange them in the correct sequence.

1
2
3
4
5
6
7

Try it yourself

Implement your solution in Solution.js in the following coding playground. We have provided the definition of the Interval class in separate files. You may add functionality to this class if you wish.

JavaScript
usercode > Solution.js
import { Interval } from './Interval.js';
import { MinHeap, MaxHeap } from './Heap.js';
/* The following definition is for MinHeap.
You can use the same methods for MaxHeap.
class MinHeap {
size(); // return number of elements
peek(); // return top element without removing
push(val); // insert element
pop(); // remove and return top element
}
*/
// The input parameter `schedule` is a list of lists, where each inner
// list contains `Interval` objects representing an employee's schedule.
function employeeFreeTime(schedule){
// Replace this placeholder return statement with your code
return [new Interval(0, 0), new Interval(0, 0)];
}
export {
employeeFreeTime
};
Employee Free Time