All Paths From Source to Target
Signals to notice
Brute force first
Not applicable — enumeration IS the problem. But in a DAG, no cycles means finite paths. It is a fair place to begin because it matches the surface of the question, yet it does not capture the deeper structure that makes the problem simpler.
The key insight
DFS/backtracking: from the source, explore each neighbor recursively. When you reach the target, record the path. Since it's a DAG, no visited set is needed. worst case. The goal is not to be clever for its own sake, but to remember the one relationship that keeps the solution grounded as you move forward.
What must stay true
In a DAG, every path from source to target is finite and non-repeating. DFS naturally enumerates all paths without needing cycle detection. If that remains true after every update, the rest of the reasoning has a stable place to stand.
Easy way to go wrong
Adding a visited set — in a DAG, you WANT to visit the same node via different paths. A visited set would prevent finding valid alternative paths. Most mistakes here are not about syntax; they come from losing track of what your state, pointer, or structure is supposed to mean.