Employee Free Time
Explore how to find common free time intervals across multiple employees by merging and intersecting their schedules. Understand how to process lists of non-overlapping intervals and develop an approach to identify shared downtime effectively in a coding interview context.
We'll cover the following...
Statement
You’re given a list containing the schedules of multiple employees. Each person’s schedule is a list of non-overlapping intervals in sorted order. An interval is specified with the start and end time, both being positive integers. Your task is to find the list of finite intervals representing the free time for all the employees.
Note: The common free intervals are calculated between the earliest start time and the latest end time of all meetings across all employees.
Constraints:
-
schedule.length,schedule[i].length -
interval.start<interval.end, whereintervalis any interval in the list of schedules.
Examples
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
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]]]
[[2, 8]]
[[6, 8]]
[[2, 6]]
[[4, 6]]
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.
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.
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 elementspeek(); // return top element without removingpush(val); // insert elementpop(); // 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 codereturn [new Interval(0, 0), new Interval(0, 0)];}export {employeeFreeTime};