Assign Incoming Jobs to Weighted Servers as They Free Up

Last updated: November 29, 2026

Quick Overview

Servers have weights; job j arrives at second j and takes tasks[j] seconds. Each job goes to the free server with the smallest weight (ties by index); if none is free, it waits for the earliest server to finish. Return the server index for every job.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Servers have weights; job j arrives at second j and takes tasks[j] seconds. Each job goes to the free server with the smallest weight (ties by index); if none is free, it waits for the earliest server to finish. Return the server index for every job.

A Google onsite simulation set on a batch-processing fleet. The interviewer checks a two-heap design (free servers by weight, busy servers by finish time) and correct handling when all servers are busy.

What the Interviewer Expects
  • Keeps a free heap keyed by (weight, index)
  • Keeps a busy heap keyed by (finish time, weight, index)
  • Releases finished servers before assigning
  • Fast-forwards when no server is free
  • States O((n + m) log n)
Key Topics to Cover
Min-Heap
Two Heaps
Simulation
Load Balancing
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 job priorities
  • What if servers can fail mid-job?
  • Report the total idle time per server
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: weights for n servers and tasks for m jobs; job j becomes available at time j.
  • Jobs are assigned in order. A waiting job gets the next server to free up; if several free at once, smalle...
High-Level Design

Two min-heaps. free holds (weight, index) for idle servers. busy holds (finish_time, weight, index). For job j, first move every busy server with finish <= j into free. If free is non-em...


Submit Your Answer
Markdown supported