Assign Incoming Jobs to the Lightest Free EC2 Host
Last updated: November 29, 2026
Quick Overview
Each host has a weight (capacity class) and an index. Job j arrives at second j with a duration. Assign each job to the free host with the smallest weight, breaking ties by smallest index; if none is free, wait for the earliest host to finish. Return each job's host index.
Amazon
November 29, 20260
0
0 solved
Each host has a weight (capacity class) and an index. Job j arrives at second j with a duration. Assign each job to the free host with the smallest weight, breaking ties by smallest index; if none is free, wait for the earliest host to finish. Return each job's host index.
An Amazon onsite simulation problem echoing how a scheduler places work on EC2 capacity. Interviewers look for two heaps, one for free hosts and one for busy hosts keyed by finish time, and careful handling of time jumps when every host is busy.
What the Interviewer Expects
- Use a min-heap of free hosts keyed by (weight, index)
- Use a min-heap of busy hosts keyed by (free_time, weight, index)
- Release all hosts whose free time is at or before the current time
- Jump time forward to the earliest finish when no host is free
- Analyze O((n + m) log n) time
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 hosts being added or removed mid-stream?
- What changes if jobs have priorities and can preempt others?
- How would you shard this scheduler across multiple machines?
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: list weights of n host weights and list durations of m job durations. Job j becomes available at time j and jobs are assigned in order. Output: list of m host indices....
High-Level Design
Free heap holds (weight, index). Busy heap holds (free_at, weight, index). For job j, set time t = max(t, j). Move every busy host with free_at <= t into the free heap. If the free heap is empty, set ...