← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Senior

SeniorPrefer not to say
Jun 2026

Summary

Got a Google SWE coding question involving task scheduling on a 24-hour wraparound timeline. The tricky part was that tasks could span midnight and even run longer than a full day, which made the naive interval overlap approach break down pretty fast.

Questions Asked (1)

Q1

Given a list of tasks defined by a start time (in minutes, 0 to 1439) and a duration (which can exceed 1440 minutes), find the minimum number of servers needed so no two tasks run simultaneously on the same server. Tasks wrap around the 24-hour cycle and run continuously.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The wraparound is what gets you.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model each task as an interval on a circular timeline, then use a sweep-line algorithm to count the maximum number of overlapping tasks. Handle durations exceeding 1440 minutes by decomposing them into full cycles plus a remainder, and account for wrap-around by splitting intervals that cross midnight or using a circular sweep.

Pro tip: Clarify with the interviewer whether tasks are fixed (non-preemptive) and whether servers can be reused immediately after a task ends. Also, mention that the answer is the maximum overlap, which equals the chromatic number for interval graphs, so a greedy assignment works.

1. Clarify assumptions and edge cases

Confirm that tasks are non-preemptive, servers can be reused immediately, and tasks run continuously. Discuss how to handle durations > 1440 minutes (e.g., a task lasting 2000 minutes occupies the server for multiple cycles).

2. Normalize intervals to a linear timeline

For each task, compute its start and end times modulo 1440. If duration >= 1440, it covers the entire cycle, so it alone requires a dedicated server; otherwise, split the interval if it wraps around midnight (e.g., start=1400, end=100 becomes [1400,1440) and [0,100)).

3. Apply sweep-line to find maximum overlap

Create events for each interval start (+1) and end (-1), sort them by time, and sweep to track the current number of active tasks. The maximum active count is the minimum number of servers needed.

4. Handle tasks with duration >= 1440 separately

For tasks that last 1440 minutes or more, they occupy a server for the entire cycle, so increment the server count by 1 for each such task and remove them from the sweep-line calculation.

5. Combine results and discuss trade-offs

Add the count of full-cycle tasks to the maximum overlap from the sweep-line. Discuss time complexity O(n log n) and space O(n), and mention alternative approaches like priority queues or greedy assignment.

Key Points to Mention

  • Circular timeline handling: split intervals that cross midnight or use a circular sweep with modulo arithmetic.
  • Durations exceeding 1440 minutes: treat as full-cycle tasks requiring dedicated servers.
  • Sweep-line algorithm: sort events and track active count to find maximum overlap.
  • Interval graph coloring: minimum servers equals maximum overlap (chromatic number).
  • Edge cases: tasks with zero duration, tasks starting at 0, tasks ending exactly at 1440.
  • Time and space complexity: O(n log n) time, O(n) space, and potential optimizations.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.