Compute the Critical Path Through a Project Timeline

Last updated: November 29, 2026

Quick Overview

Each task has a duration in days and a set of blocking tasks. Return the minimum number of days to finish the whole project and one chain of tasks that determines that length.

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

0

0

0 solved


Each task has a duration in days and a set of blocking tasks. Return the minimum number of days to finish the whole project and one chain of tasks that determines that length.

Asana's timeline view shows dependencies across a project plan, and project managers want to know which tasks cannot slip. The interviewer checks that you see this as a longest path in a DAG, compute it in linear time with topological order, and reconstruct the path, not just the number.

What the Interviewer Expects
  • Identifies the problem as longest path in a DAG weighted by task duration
  • Processes tasks in topological order computing earliest start and finish
  • Tracks a predecessor pointer to reconstruct the critical chain
  • Detects cycles and reports them
  • Explains slack and how it falls out of a backward pass
Key Topics to Cover
DAG longest path
topological sort
critical path method
dynamic programming
path reconstruction
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 would you compute each task's slack (how late it can start without delaying the project)?
  • How would you update the critical path when one task's duration changes?
  • What if some tasks can run only when a specific person is free?
  • How would you return all critical paths when there are ties?
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: {task: duration} and (blocker, blocked) pairs. Tasks start as soon as all blockers finish, with unlimited parallelism. Output: (project_length, critical_path). An empty project returns `(...

High-Level Design

Earliest start of a task is the maximum earliest finish of its blockers, which is a DP over a topological order. The project length is the maximum finish. Remembering which blocker gave the maximum le...


Submit Your Answer
Markdown supported

Related Questions