Order Batch Jobs to Minimize Total Weighted Completion Time

Last updated: November 29, 2026

Quick Overview

A single Borg worker must run n batch jobs back to back, each with a processing time and a priority weight. Choose an order that minimizes the sum over jobs of weight times completion time, and return that minimum.

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

0

0

0 solved


A single Borg worker must run n batch jobs back to back, each with a processing time and a priority weight. Choose an order that minimizes the sum over jobs of weight times completion time, and return that minimum.

Scheduling is core to Google infrastructure, and this question checks whether a candidate can derive Smith's ratio rule from an adjacent-swap argument instead of guessing. Interviewers often ask for the proof before the code.

What the Interviewer Expects
  • Define completion time and the objective clearly
  • Compare two adjacent jobs and derive the swap condition
  • Sort by processing time over weight ascending
  • Use cross-multiplication to avoid floating point error
  • Handle zero weights
Key Topics to Cover
Greedy
Exchange argument
Scheduling
Smith's rule
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
  • Jobs have release times. Is the problem still easy?
  • Two identical workers instead of one.
  • Minimize the maximum weighted lateness given deadlines.
  • Weights change online as jobs arrive; how would you keep the order?
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 (time, weight) with time > 0, weight >= 0. Completion time of a job is the sum of times of jobs before it plus its own. Output: the minimum of the sum of weight * completion....

High-Level Design

Take two adjacent jobs i then j starting at time T. Their contribution is w_i (T + t_i) + w_j (T + t_i + t_j). Swapping gives w_j (T + t_j) + w_i (T + t_j + t_i). The difference is `w_j t_i - w_i ...


Submit Your Answer
Markdown supported