Enumerate Every Path From Source to Sink in a Pipeline DAG
Last updated: November 29, 2026
Quick Overview
Given a directed acyclic graph of n pipeline stages where stage 0 is the source and stage n-1 is the sink, return every path from source to sink.
0
0
0 solved
Given a directed acyclic graph of n pipeline stages where stage 0 is the source and stage n-1 is the sink, return every path from source to sink.
A technical screen style question about a data pipeline DAG, the kind of workflow a Dataflow or internal orchestrator runs. It tests DFS with backtracking and whether you can reason about output-sensitive complexity, since the number of paths can be exponential.
What the Interviewer Expects
- Use DFS with a current path that you push and pop
- Rely on the DAG property so no visited set is needed
- Copy the path when you reach the sink
- Explain exponential output size
- Offer a memoized count when only the number of paths is needed
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
- Return only the count of paths, for a DAG with 10^5 nodes.
- Return the longest path by total stage runtime.
- What changes if the graph might contain cycles?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input:
graph[i]lists stages that consume stagei's output. - Graph is acyclic.
- Output: all paths from 0 to n-1, each as a list of stage ids....
High-Level Design
DFS from stage 0, keeping a single path list. On entering a node, append it; if it is the sink, record a copy; then recurse into children and pop on return. Because the graph has no cycles, we can n...