Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Binary Tree Paths
Bookmark
String Concat
Backtracking List
Iterative Stack
Input
Complete Tree
Three Levels (4 paths)
Left Skewed
Right Skewed
Custom
tree
=
[1, 2, 3, 4, 5]
1
2
3
4
5
path
paths
collect every
root-to-leaf
path
1
2
3
4
5
path
paths
collect every
root-to-leaf
path
1
2
3
4
5
path
1
paths
path = "
1
"
1
2
3
4
5
path
1
->
2
paths
path = "
1->2
"
1
2
3
4
5
path
1
->
2
paths
go left from
2
1
2
3
4
5
path
1
->
2
->
4
paths
1->2->4
leaf 4: paths += "
1->2->4
"
1
2
3
4
5
path
1
->
2
->
5
paths
1->2->4
path = "
1->2->5
"
1
2
3
4
5
path
1
paths
1->2->4
1->2->5
backtrack: path = "
1
"
1
2
3
4
5
path
1
paths
1->2->4
1->2->5
go right from
1
1
2
3
4
5
path
1
->
3
paths
1->2->4
1->2->5
1->3
leaf 3: paths += "
1->3
"
1
2
3
4
5
path
paths
1->2->4
1->2->5
1->3
return ["1->2->4", "1->2->5", "1->3"]
algo
master
.
io
Step:
Start: collect every root-to-leaf path
0 / 16
Input
Complete Tree
Three Levels (4 paths)
Left Skewed
Right Skewed
Custom
tree
=
[1, 2, 3, 4, 5]
0 / 16
algo
master
.
io
Step:
Start: collect every root-to-leaf path