Schedule TPU Jobs With a Cooldown Between Same-Type Runs
Last updated: November 29, 2026
Quick Overview
Jobs are labeled by type. Each time unit runs one job or stays idle, and two jobs of the same type must be at least n time units apart. Return the minimum total time to run all jobs.
0
0
0 solved
Jobs are labeled by type. Each time unit runs one job or stays idle, and two jobs of the same type must be at least n time units apart. Return the minimum total time to run all jobs.
A classic Google onsite scheduling question placed on a TPU pod where reloading the same model needs a cooldown. The interviewer looks for either the max-heap simulation or the counting formula, and expects the candidate to explain why both agree.
What the Interviewer Expects
- Uses a max-heap of remaining counts with a cooldown queue
- Or derives the (maxCount - 1) * (n + 1) + ties formula
- Explains idle slots and when they vanish
- Handles n = 0
- States O(total jobs log k) or O(total) time
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Return an actual schedule, not just its length
- What if jobs must run in the given order?
- What if different types have different cooldowns?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: list of job types (letters) and cooldown n >= 0.
- Each unit of time runs one job or idles.
- Same-type jobs need at least n units between them.
- Output: minimum number of time units....
High-Level Design
Greedy: at every time step, run the available type with the most jobs remaining, because the most frequent type is the one most likely to force idles later. Simulate with a max-heap of remaining count...