Compute minimum servers for cyclic tasks
Company: Google
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates understanding of interval scheduling, overlap detection, and handling cyclic time via modular arithmetic for tasks that wrap past midnight, reflecting competency in reasoning about resource allocation on continuous timelines.
Constraints
- 0 <= len(tasks) <= 200000
- 0 <= start_i < 1440
- 1 <= duration_i <= 1000000000
- Each task occupies the interval [start_i, start_i + duration_i)
Examples
Input: ([(1380, 60), (0, 30), (1380, 30)],)
Expected Output: 2
Explanation: The tasks at 1380 overlap with each other, so 2 servers are needed. The task from 0 to 30 does not overlap with them.
Input: ([],)
Expected Output: 0
Explanation: No tasks means no servers are needed.
Input: ([(0, 60), (60, 15), (30, 30)],)
Expected Output: 2
Explanation: The first and third tasks overlap on [30, 60). The second starts exactly at 60, so it can reuse a server from a task that ended at 60.
Input: ([(10, 2000), (20, 100), (50, 1000), (60, 10)],)
Expected Output: 4
Explanation: From time 60 to 70, all four tasks are running simultaneously, so 4 servers are required.
Input: ([(0, 1440), (1439, 2), (1439, 1)],)
Expected Output: 3
Explanation: Between 1439 and 1440, all three tasks are active at once, including the ones that wrap past midnight.
Hints
- Do not split a wrapping task by day boundaries. Treat every task as one interval on a single increasing timeline: [start, start + duration).
- The answer is the maximum number of intervals active at the same time. Sort start/end events and sweep from left to right.