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.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

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
DFS
backtracking
DAG
path enumeration
memoization
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
  • 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 Problems
Sample Answer
Requirements
  • Input: graph[i] lists stages that consume stage i'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...


Submit Your Answer
Markdown supported