Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
All Paths From Source to Target
Bookmark
DFS + Backtracking
BFS + Paths
DFS + Memo
Input
Diamond
Complex
Two nodes
Fan-out
Chain + skip
Custom
graph
=
[[1,2],[3],[3],[]]
0
0
1
1
2
2
3
3
source
target
0
0
1
1
2
2
3
3
source
target
0
0
1
1
2
2
3
3
source
target
current
follow
0 → 1
0
0
1
1
2
2
3
3
source
target
current
follow
1 → 3
0
0
1
1
2
2
3
3
source
target
current
[0,1,3]
→ reaches the target
0→1→3
0
0
1
1
2
2
3
3
source
target
current
node 1
→ every neighbor explored, return
0→1→3
0
0
1
1
2
2
3
3
source
target
current
dfs(2)
paths from 2 to 3
0→1→3
0
0
1
1
2
2
3
3
source
target
current
dfs(3)
paths from 3 to 3
0→1→3
0
0
1
1
2
2
3
3
source
target
current
pop
→ path is
[0,2]
0→1→3
0→2→3
0
0
1
1
2
2
3
3
source
target
current
pop
→ path is
[0]
0→1→3
0→2→3
0
0
1
1
2
2
3
3
source
target
return 2
paths
0→1→3
0→2→3
algo
master
.
io
Step:
Find every path from node 0 to node 3 by walking one path at a time
0 / 19
Input
Diamond
Complex
Two nodes
Fan-out
Chain + skip
Custom
graph
=
[[1,2],[3],[3],[]]
0 / 19
algo
master
.
io
Step:
Find every path from node 0 to node 3 by walking one path at a time