← Questions
Minimum servers for daily jobs that wrap past midnight
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Google's first round (coding), last asked Feb 2026. It tests intervals, sorting and heaps.
Each job runs every day during a fixed window on a 24-hour clock, given as [start, end) in hours. A window can wrap past midnight: when start > end, the job runs from start to midnight and from midnight to end. A server runs one job at a time and jobs run every day forever. Return the fewest servers needed so every job always has a server.
Interface
Unless you agree on a different interface with the interviewer, assume:
-
min_servers(jobs: list[tuple[int, int]]) -> int— each job is(start, end)with0 <= start, end < 24andstart != end; windows are half-open.
Example
[(22, 2), (1, 3), (4, 6)] -> 2 # 22-2 and 1-3 overlap between 1 and 2
[(22, 2), (1, 3), (2, 23)] -> 2 # never more than two at once; 22-2 ends as 2-23 starts
[(9, 17), (17, 9)] -> 1 # back to back around the clock
Constraints
- Up to 10^5 jobs.
- Times are whole hours here; the method should not depend on that.
Clarifying questions
- Are windows half-open, so one job may start the moment another ends?
- What does
start == endmean: an empty job or a full day? - Must a job stay on the same server every day, or can it move?
- Do times have minutes or seconds?
What a strong answer covers
- The link to the classic meeting-rooms count: the answer is the maximum number of jobs running at the same moment.
- Handling wrap-around by splitting a wrapping job into
[start, 24)and[0, end), or by counting jobs active at midnight as the starting load. - A sweep over sorted start and end events, processing ends before starts at equal times, O(n log n); or a difference array over the 24 hours when times are coarse.
- Whether the maximum overlap is really enough: if a job may use a different server on different days, yes (each day's runs are ordinary intervals); if a job must keep one server forever, it can need more, e.g.
[(0, 10), (8, 18), (16, 2)]has at most two jobs at once yet needs three fixed servers. - Tests: no wrapping jobs, all jobs wrapping, touching windows.
Follow-ups
- Return which server runs each job.
- Jobs repeat on different days of the week.
- Jobs arrive and leave over time: keep the answer current.
Where it's asked
- Google · First round: coding · Last asked Feb 202645 min · Coding in a Google Doc, no syntax highlighting or autocomplete · No AI
What it tests
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
