← All Exercises
Find the Critical Path Through Task Dependencies
intermediatejavascript
Background
Delivery estimates that add up all tasks ignore parallelism. The critical path is the only chain whose delay actually moves the end date.
Problem
Compute the longest-duration dependency chain in a task graph and report the ordered path plus its total duration.
Input
JSON object: { tasks: [{ id, durationDays, dependsOn?: string[] }] }Output
JSON object: { path: string[], totalDays: number }Sample tests
Sample 1
Input: {"tasks":[{"id":"design","durationDays":3},{"id":"api","durationDays":5,"dependsOn":["design"]},{"id":"ui","durationDays":2,"dependsOn":["design"]}]}Expected: {"path":["design","api"],"totalDays":8}Sample 2
Input: {"tasks":[{"id":"a","durationDays":2},{"id":"b","durationDays":9},{"id":"c","durationDays":1,"dependsOn":["a"]}]}Expected: {"path":["b"],"totalDays":9}Your solution
Learning objective
Estimate delivery from dependency structure rather than task totals.