Earliest Finish Time for a Build Graph With Task Durations

Last updated: November 29, 2026

Quick Overview

Given n build tasks with durations and prerequisite pairs (a must finish before b starts), with unlimited parallel workers, return the minimum total time to finish all tasks.

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

0

0

0 solved


Given n build tasks with durations and prerequisite pairs (a must finish before b starts), with unlimited parallel workers, return the minimum total time to finish all tasks.

An onsite question grounded in distributed builds and CI pipelines, where wall-clock time is limited by the critical path rather than total work. The interviewer checks that you use topological order to compute each task's earliest finish and recognize the answer as the longest weighted path in a DAG.

What the Interviewer Expects
  • Model tasks as a DAG and run Kahn's algorithm
  • Compute earliest finish = duration + max finish of prerequisites
  • Return the maximum earliest finish over all tasks
  • Detect cycles and report them as invalid
  • Identify the critical path for the follow-up
Key Topics to Cover
topological sort
DAG longest path
critical path
Kahn's algorithm
dynamic programming on DAG
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
  • Return the tasks on the critical path.
  • What if only k workers are available?
  • Which single task, if sped up, shortens the total time most?
  • How would you update the answer when one duration changes?
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: n, durations[i], relations as (prev, next) with 0-based ids.
  • Unlimited parallelism.
  • Output: minimum makespan, or -1 if there is a cycle....
High-Level Design

With unlimited workers, each task starts the moment its last prerequisite finishes. So finish[v] = durations[v] + max(finish[u] for u in prereqs(v)), with 0 when there are none. That recurrence need...


Submit Your Answer
Markdown supported