Assign Upload Jobs to the Lightest Free Encoding Server
Last updated: November 29, 2026
Quick Overview
Servers have weights; job j arrives at second j with a duration. Each arriving job goes to the free server with the smallest weight (then smallest index), waiting for the earliest server to free up if none are free. Return the server index for each job.
Meta
November 29, 20260
0
0 solved
Servers have weights; job j arrives at second j with a duration. Each arriving job goes to the free server with the smallest weight (then smallest index), waiting for the earliest server to free up if none are free. Return the server index for each job.
A Meta onsite simulation on a two-heap pattern, framed around video encoding servers. Interviewers check that you move servers between a free heap and a busy heap correctly and advance time when everything is busy.
What the Interviewer Expects
- Use a free heap keyed by (weight, index)
- Use a busy heap keyed by (free_time, weight, index)
- Release all servers whose free time has passed before assigning
- Jump time forward when no server is free
- Analyze O((n + m) log n)
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
- What if jobs have priorities and the queue is not FIFO?
- How would this change with heterogeneous server speeds?
- Report the average queueing delay.
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:
server_weights(n) andjob_durations(m); job j becomes available at time j. - Jobs are assigned in arrival order (FIFO).
- When several servers free up at the same time, the lightest wi...
High-Level Design
Two heaps:
free:(weight, index)of idle servers.busy:(time_free, weight, index)of working servers.
For job j, set time = max(time, j). If no server is free, jump time to the earli...