Makespan of a Build Graph Run on K Parallel Workers

Last updated: November 29, 2026

Quick Overview

A build has tasks with durations and prerequisite edges forming a DAG. K identical workers run tasks; whenever a worker is free, it takes the ready task with the smallest id, and a task becomes ready when all its prerequisites finish. Return the time the whole build finishes and each task's start time, or -1 if there is a cycle.

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

0

0

0 solved


A build has tasks with durations and prerequisite edges forming a DAG. K identical workers run tasks; whenever a worker is free, it takes the ready task with the smallest id, and a task becomes ready when all its prerequisites finish. Return the time the whole build finishes and each task's start time, or -1 if there is a cycle.

A Google onsite question in the setting of distributed builds like Bazel remote execution. It checks that you combine topological dependency tracking with a discrete event simulation, handle simultaneous completions correctly, and detect cycles.

What the Interviewer Expects
  • Track remaining prerequisite counts per task
  • Keep a min-heap of ready tasks and a min-heap of running tasks by finish time
  • Release all tasks finishing at the same time before assigning new work
  • Advance time to the next finish event, never tick
  • Detect a cycle when work remains but nothing is ready or running
Key Topics to Cover
discrete event simulation
topological sort
heap
scheduling
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
  • How does the makespan compare with the critical path length, and when are they equal?
  • Would scheduling by longest remaining path first improve the makespan? Why?
  • How would you handle workers with different speeds?
  • What if task durations are only known after they run?
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

Inputs: durations list for tasks 0..n-1, deps list of (a, b) meaning a must finish before b starts, and k workers. Ready tie-break by smallest id. A task finishing at time t frees its worker a...

High-Level Design

Compute indeg and adjacency. Push all zero-indegree tasks into ready. Loop: while workers are free and ready is non-empty, pop the smallest id, record its start at t, push (t + duration, id)...


Submit Your Answer
Markdown supported