PIXELBANKv9.1.0
Menu

Critical Path Length of a Pipeline DAG

Problem Statement

Compute the minimum total time to run a CI pipeline where independent stages run in parallel β€” the critical path (longest-duration path) through the dependency DAG.

Background

Each stage has a duration and depends on prior stages. A stage cannot start until all its dependencies finish. The earliest finish time of a stage is duration + max(earliest finish of its deps) (or just its duration if it has none). The pipeline's makespan is the maximum finish time over all stages.

Your Task

def critical_path(stages):
  • stages: dict mapping name -> {"duration": number, "deps": [names]}.
  • Return the makespan (number). Assume the DAG is acyclic.

Input Format

  • stages (dict).

Output Format

  • A number (total time).

Sample

print(critical_path({"a": {"duration": 3, "deps": []}, "b": {"duration": 4, "deps": ["a"]}}))

Output:

7

Example:

Input:
print(critical_path({"a": {"duration": 3, "deps": []}, "b": {"duration": 4, "deps": ["a"]}}))
Output:
7
Reasoning:
  • Identify the dependency chain: Stage "b" depends on stage "a", so "a" must finish before "b" can start.
  • Calculate the earliest finish time for stage "a": Since it has no dependencies, its finish time is simply its duration, 33.
  • Calculate the earliest finish time for stage "b": It waits for its dependency "a" to finish, so its start time is 33; adding its own duration gives 3+4=73 + 4 = 7.
  • Determine the pipeline makespan: This is the maximum finish time across all stages, which is max⁑(3,7)=7\max(3, 7) = 7.
  • The final output is 7

Constraints:

  • finish(stage) = duration + max(finish(dep)) (0 if no deps).
  • Makespan = max finish over all stages.
  • DAG is acyclic; use memoization.
πŸ”’

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.