Dispatch Upload Transcode Jobs to Workers by Priority
Last updated: November 29, 2026
Quick Overview
Upload transcode jobs arrive as (job_id, arrival_time, duration, priority), where a lower priority number is more urgent. With m identical workers, whenever a worker is free it takes the most urgent job that has already arrived (ties by earlier arrival, then job_id). Return the order in which jobs finish.
TikTok
November 29, 20260
0
0 solved
Upload transcode jobs arrive as (job_id, arrival_time, duration, priority), where a lower priority number is more urgent. With m identical workers, whenever a worker is free it takes the most urgent job that has already arrived (ties by earlier arrival, then job_id). Return the order in which jobs finish.
Every TikTok upload fans out into transcode jobs, and creators with time-sensitive content (for example, LIVE replays) may get higher priority. This onsite simulation checks that you can drive time forward with two heaps and avoid busy-waiting through empty periods.
What the Interviewer Expects
- Sorts jobs by arrival and uses a pointer to release them into a ready heap
- Uses a second heap of worker free times to advance the clock
- Jumps the clock forward when nothing is ready instead of ticking one unit at a time
- Breaks ties deterministically
- Discusses starvation of low-priority jobs and aging
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 prevent low-priority jobs from starving?
- How would you support preemption when an urgent job arrives?
- How does this map to a real distributed queue like Kafka plus a worker pool?
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_id, arrival, duration, priority), integerm >= 1. - Output: list of job IDs in finish order (ties in finish time by job_id).
- Non-preemptive: a started job runs to completio...
High-Level Design
Two heaps:
ready: jobs that have arrived and wait, keyed by(priority, arrival, job_id).running:(finish_time, job_id)for jobs on workers.
Loop: the clock is the earliest event. Relea...