Problem
FAANG · LeetCode #759

Employee Free Time — three-stage drill

1The ProblemHard

Employee Free Time

Time windows when EVERY employee is free at the same time.

find time windows when EVERY employee is free (gaps in the union of busy blocks)E1[1,3][6,8]E2[2,4][7,11]E3[9,12]02468101214free [4,6]return[[4,6]]
Examples
[[[1,3],[6,8]],[[2,4],[7,11]],[[9,12]]]→ [[4,6]][[[1,2],[5,6]],[[1,3]],[[4,10]]]→ [[3,4]]

constraintEach employee's blocks are already sorted and non-overlapping; output free intervals must have positive length.

2The PatternTIME O(n log n) · SPACE O(n)

Intervals

Given a pile of ranges, sort them by start — now any overlap is a neighbour, so a single left→right pass handles them.

sort the ranges by start, then sweep once01234567891011[7,9][2,5][1,3][8,10]given: a pile of ranges in any order
Problems using this pattern
3The SolutionRESULT → [[4,6]]

Step through it

given — three separate schedulesE1[1,3][6,8]E2[2,4][7,11]E3[9,12]02468101214
given: 3 employees' schedules · find times when EVERYONE is free
Step 1 / 8
Arrow keys to navigate · escape to reset

All problems by pattern

Backtracking

Recursive Descent