Employee Free Time
HardExtra practice. This problem has no walkthrough slides. Try solving it with the pattern template on your own, and lean on the hints if you get stuck.
Question
You get schedules, a list where each entry is one employee's working blocks for the day. Every employee's own blocks are sorted and don't overlap each other, but blocks from different employees might. 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]]
Combining every block, the company is covered by [1, 3] and [4, 10] with a single shared gap in between.
Input: schedules = [[[1, 3], [5, 6]]]
Output: [[3, 5]]
With one employee, their own idle time between blocks is free time shared by everyone.
Input: schedules = [[[1, 3]], [[3, 6]]]
Output: []
One employee's block ends exactly when the other's begins, so the company is covered without any gap.
Clarify the problem
What are some questions you'd ask an interviewer?
Understand the problem
Take a moment to understand the problem and think of your approach before you start coding.