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
Coding & Algorithms
Software Engineer
TikTok
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

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
heaps
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
  • 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 Problems
Sample Answer
Requirements
  • Input: list of (job_id, arrival, duration, priority), integer m >= 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:

  1. ready: jobs that have arrived and wait, keyed by (priority, arrival, job_id).
  2. running: (finish_time, job_id) for jobs on workers.

Loop: the clock is the earliest event. Relea...


Submit Your Answer
Markdown supported