Learn
Practice
Newsletter
Resources
Mobile
New
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Find Duplicate Subtrees
Bookmark
Input
Example 1
Example 2
Example 3
Custom
tree
=
[1, 2, 3, 4, null, 2, 4, null, null, 4]
1
2
3
4
2
4
4
ids
result
identical subtrees share one serialization id
1
2
3
4
2
4
4
ids
result
identical subtrees share one serialization id
1
2
3
4
2
4
4
ids
result
lookup(
4
)
1
2
3
4
2
4
4
#1
ids
#1 ×1
result
count[#1] =
1
1
2
3
4
2
4
4
#2
#1
ids
#1 ×1
#2 ×1
result
return
#2
1
2
3
4
2
4
4
#2
#1
ids
#1 ×1
#2 ×1
result
lookup(
4
)
1
2
3
4
2
4
4
#2
#1
#1
ids
#1 ×2
#2 ×1
result
count[#1] =
2
1
2
3
4
2
4
4
#2
#1
#2
#1
ids
#1 ×2
#2 ×2
result
4
count[#2] =
2
0
1
2
3
4
2
4
4
#2
#1
#2
#1
ids
#1 ×2
#2 ×2
result
4
2
null child: id
0
1
2
3
4
2
4
4
#2
#3
#1
#2
#1
#1
ids
#1 ×3
#2 ×2
#3
result
4
2
ser = "
3,2,1
": new shape, id
#3
1
2
3
4
2
4
4
#4
#2
#3
#1
#2
#1
#1
ids
#1 ×3
#2 ×2
#3 ×1
#4 ×1
result
4
2
return [4, 2]
algo
master
.
io
Step:
Start: identical subtrees produce identical serializations
0 / 54
Input
Example 1
Example 2
Example 3
Custom
tree
=
[1, 2, 3, 4, null, 2, 4, null, null, 4]
0 / 54
algo
master
.
io
Step:
Start: identical subtrees produce identical serializations