Simulate a Priority Queue of Inference Jobs Across GPUs

Last updated: November 29, 2026

Quick Overview

Given jobs with name, arrival time, duration and priority (lower number is more urgent) and a fixed number of GPUs, simulate non-preemptive scheduling where any free GPU takes the most urgent waiting job, and return job names in completion order.

OpenAI
Coding & Algorithms
Software Engineer
OpenAI
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Given jobs with name, arrival time, duration and priority (lower number is more urgent) and a fixed number of GPUs, simulate non-preemptive scheduling where any free GPU takes the most urgent waiting job, and return job names in completion order.

OpenAI runs batch and priority tiers of inference traffic on shared GPU capacity, so simulating a scheduler is a realistic question that also tests event-driven simulation skills. Interviewers watch for two heaps (waiting by priority, running by finish time), correct time jumps when nothing can start, and explicit tie-breaking.

What the Interviewer Expects
  • Sort jobs by arrival and stream them into a waiting heap
  • Use a running heap keyed by finish time to free GPUs
  • Advance time to the next event instead of ticking one unit at a time
  • Define tie-breaks for equal priority and equal finish times
  • Handle idle gaps where no jobs are waiting
Key Topics to Cover
heaps
discrete event simulation
scheduling
priority queues
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Add preemption: a more urgent job can evict a running lower-priority job. What state is needed?
  • Prevent starvation of low-priority jobs with aging.
  • Jobs need different numbers of GPUs: what changes, and what new problem appears?
  • Report average wait time per priority class.
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Job tuple: (name, arrival, duration, priority).
  • A free GPU immediately starts the waiting job with the smallest (priority, arrival, name).
  • No preemption. A job arriving exactly when a GPU fr...
High-Level Design

Run a discrete event loop. At each step, if nothing can start right now, jump t to the earliest of the next arrival or the next finish. Then retire every running job finished by t (freeing GPUs), ...


Submit Your Answer
Markdown supported