Employee Free Time

Hard

This is an extra practice problem. It doesn't have walkthrough slides. You can solve it with the pattern template you already know. Open the hints if you get stuck.

Question

You get schedules, a list where each entry is one employee's working blocks for the day. Each employee's own blocks are sorted and don't overlap each other. Blocks from different employees can overlap, though. Return every stretch of time where every single employee is free, sorted by start value. Only report a stretch if it has a positive length and falls between the earliest and latest working blocks in the whole company.

Input: schedules = [[[1, 2], [5, 6]], [[1, 3]], [[4, 10]]]

Output: [[3, 4]]

When you combine every block, the company is covered by [1, 3] and [4, 10]. That leaves one shared gap in between.

Input: schedules = [[[1, 3], [5, 6]]]

Output: [[3, 5]]

When there's only one employee, the free time between their blocks counts as everyone's free time.

Input: schedules = [[[1, 3]], [[3, 6]]]

Output: []

One employee's block ends exactly when the other's begins. That means the company is covered with no gap at all.

Clarify the problem

What are some questions you'd ask an interviewer?

Understand the problem

What is the shared free time for this company? schedules = [[[1, 10]], [[2, 5]], [[6, 9]]]
[[5, 6]]
[]
[[1, 2], [9, 10]]
[[10, 20]]

Remember to understand the problem and plan your approach before you start coding.