Problem
FAANG · LeetCode #253

Meeting Rooms II — three-stage drill

1The ProblemMedium

Meeting Rooms II

Fewest rooms to fit every meeting — the peak number of concurrent meetings.

meetings can overlap — what's the fewest rooms that fits all of them?meetingsA [0,8)B [2,6)C [5,10)D [9,12)02468101214at t=5 → 3 meetings are in progress at oncereturn3
Examples
[[0,30],[5,10],[15,20]]→ 2[[7,10],[2,4]]→ 1

constraintHalf-open intervals — a meeting ending at t and another starting at t share a room (end event processed before start at equal t).

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 → 3

Step through it

meetingsA [0,8)B [2,6)C [5,10)D [9,12)02468101214
given: 4 meetings · how many rooms do we need so every meeting has one?
Step 1 / 11
Arrow keys to navigate · escape to reset

All problems by pattern

Backtracking

Recursive Descent