Employee Free Time
Employee Free Time gives each worker a sorted, non-overlapping schedule and asks for every finite interval when all employees are free, excluding zero-length gaps.
We'll cover the following...
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[0][0].start = 1andschedule[0][0].end = 2, whileschedule[0][0][0]is invalid. Do not include intervals with zero length (for example,[3, 3]) in the output.
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 main.py in the following coding playground. We have provided the definition of the Interval class in the other file. You may add functionality to this class if you wish.
from interval import Interval# The input parameter `schedule` is a list of lists, where each inner# list contains `Interval` objects representing an employee's schedule.def employee_free_time(schedule):# Replace this placeholder return statement with your codereturn [Interval(0, 0), Interval(0, 0)]