Consolidate On-Call Rotations
Learn this problemProblem statement
You are given a list of on-call rotations. Each rotation has a name, start time, and end time, representing a half-open interval [start, end) during which that person is on call.
Produce the consolidated on-call timeline as maximal contiguous segments. In each output segment, the set of on-call people must remain constant throughout the entire interval. Sort segments by start time and omit gaps where nobody is on call.
Represent each input row as [name, start, end]. Return each output row as [start, end, names], where names is a comma-separated list of on-call names in lexicographic order.
Function
consolidateOnCallRotations(rotations: String[][]) → String[][]Examples
Example 1
rotations = [["A", "10", "50"], ["B", "20", "60"], ["C", "30", "40"], ["D", "30", "40"]]return = [["10", "20", "A"], ["20", "30", "A,B"], ["30", "40", "A,B,C,D"], ["40", "50", "A,B"], ["50", "60", "B"]]The original interview report presents this example as input and output tables.
Input rotations
| name | start | end |
|---|---|---|
A | 10 | 50 |
B | 20 | 60 |
C | 30 | 40 |
D | 30 | 40 |
Consolidated schedule
| start | end | names |
|---|---|---|
10 | 20 | A |
20 | 30 | A, B |
30 | 40 | A, B, C, D |
40 | 50 | A, B |
50 | 60 | B |
The active set changes at times 10, 20, 30, 40, 50, and 60.
Constraints
1 <= rotations.length <= 2 * 10^5- Each row is
[name, start, end]. 0 <= start < end <= 10^9- Multiple rotations may share the same start or end time.
More Google problems
- Deduplicate Logs: Keep FirstONSITE INTERVIEW · Seen Jul 2026
- Deduplicate Logs: Keep LatestONSITE INTERVIEW · Seen Jul 2026
- Find a Template Across Binary-Tree LeavesONSITE INTERVIEW · Seen Jul 2026
- Maximum Programmer-Problem MatchingONSITE INTERVIEW · Seen Jul 2026
- Minimum Direction ViolationsONSITE INTERVIEW · Seen Jul 2026
- Stream Latest Log VersionsONSITE INTERVIEW · Seen Jul 2026
- Stream Unique Logs in Timestamp OrderONSITE INTERVIEW · Seen Jul 2026
- Top-K IP Addresses from File RecordsONSITE INTERVIEW · Seen Jul 2026