Minimum Kitchen Time for Dependent Prep Steps With a Critical Path
Last updated: November 29, 2026
Quick Overview
Given kitchen prep steps with durations and before/after dependencies, compute the minimum time to finish all steps with unlimited cooks working in parallel, return the critical path, and report a cycle as impossible.
DoorDash
November 29, 20260
0
0 solved
Given kitchen prep steps with durations and before/after dependencies, compute the minimum time to finish all steps with unlimited cooks working in parallel, return the critical path, and report a cycle as impossible.
DoorDash cares about accurate food prep time because it drives when a Dasher is dispatched to the store. This topological sort question asks for the longest path in a DAG, which is what sets the earliest ready time, and checks cycle detection and path reconstruction.
What the Interviewer Expects
- Recognize the answer is the longest path in a DAG, not the sum
- Use Kahn's algorithm so cycle detection comes for free
- Relax finish times along edges in topological order
- Reconstruct the critical path with parent pointers
- Explain how limited cooks would make the problem NP-hard in general
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would the answer change with only two cooks?
- How would you find steps with slack that can be delayed without delaying the order?
- How would you update the answer quickly 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 ProblemsSample Answer
Requirements
durations: step to minutes;deps: list of(before, after).- A step starts once all its prerequisites finish; unlimited parallel cooks.
- Output:
(total_minutes, critical_path), or `(-1, [])...
High-Level Design
Initialize finish[s] = durations[s], the finish time if s started at zero. Process steps in Kahn order (indegree zero first). For each edge u -> v, v cannot finish before `finish[u] + durations[...