Optimize Job Routing in Parallel Machine Scheduling
Company: TikTok
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Overview: This question evaluates understanding of online scheduling and algorithmic decision-making, specifically skills in minimizing average flow-time when routing jobs to parallel machines.
Constraints
- 1 <= n <= 2 * 10^5
- times[i] is an integer in [1, 10^9]
- Two identical, non-preemptive machines
- All jobs are available at time 0
- Return the minimal total completion time (sum over all jobs)
Hints
- Minimizing average flow-time equals minimizing total completion time.
- Sort processing times in nondecreasing order (SPT).
- Maintain a min-heap of machine availability times (start with [0,0]).
- For each job p in sorted times: pop earliest available time t, push back t+p, and add t+p to the answer.