Assign Training Jobs to the Earliest Available GPU
Last updated: November 29, 2026
Quick Overview
Jobs arrive in order with (arrival_time, duration). Each job runs on the lowest-numbered idle GPU at its arrival; if all n GPUs are busy, it waits and runs on whichever GPU frees first (lower id on ties), keeping its duration. Return each job's GPU and start time, and the GPU that ran the most jobs.
NVIDIA
November 29, 20260
0
0 solved
Jobs arrive in order with (arrival_time, duration). Each job runs on the lowest-numbered idle GPU at its arrival; if all n GPUs are busy, it waits and runs on whichever GPU frees first (lower id on ties), keeping its duration. Return each job's GPU and start time, and the GPU that ran the most jobs.
A heap simulation used in NVIDIA screens for cluster and DGX Cloud scheduling teams. Interviewers check that you keep two heaps with the right keys, release finished GPUs before choosing, and correctly delay jobs that must wait.
What the Interviewer Expects
- Uses a min-heap of idle GPU ids and a min-heap of (finish_time, gpu) for busy GPUs
- Moves every GPU whose finish time is at or before the arrival back to idle first
- Handles the waiting case by popping the earliest finishing GPU and delaying the start
- Breaks ties deterministically and counts runs per GPU
- States O(m log n) complexity
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
- How would you support job priorities so a waiting high-priority job jumps the queue?
- What changes if a job needs g GPUs at once (gang scheduling)?
- How would you compute the average wait time and GPU utilization from the output?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Inputs: num_gpus, jobs sorted by arrival. A GPU that finishes at time t is free for a job arriving at t. Waiting jobs are served in arrival order, which the sequential loop guarantees. Output: GPU...
High-Level Design
Two heaps. idle holds GPU ids so the smallest id pops first. busy holds (finish_time, gpu) so the earliest finishing GPU, with lower id on ties, pops first. For each job, drain from busy every...