Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Minimum Distance Between BST Nodes
Bookmark
Sorting
Inorder List
Prev Pointer
Input
Example 1
Example 2
Example 3
Custom
tree
=
[4, 2, 6, 1, 3]
4
2
6
1
3
minDiff = ∞
gather values, order them, then scan adjacent gaps
4
2
6
1
3
minDiff = ∞
gather values, order them, then scan adjacent gaps
4
2
6
1
3
minDiff = ∞
values
4
gather
4
onto the strip
4
2
6
1
3
minDiff = ∞
values
4
2
gather
2
onto the strip
4
2
6
1
3
minDiff = ∞
values
4
2
1
3
gather
3
onto the strip
4
2
6
1
3
minDiff = ∞
values
4
2
1
3
6
gather
6
onto the strip
4
2
6
1
3
minDiff = ∞
sorted
1
2
3
4
6
sort the gathered values into ascending order
4
2
6
1
3
minDiff = 1
sorted
1
2
3
4
6
2 - 1 =
1
→ new minimum
4
2
6
1
3
minDiff = 1
sorted
1
2
3
4
6
4 - 3 =
1
4
2
6
1
3
minDiff = 1
sorted
1
2
3
4
6
6 - 4 =
2
4
2
6
1
3
minDiff = 1
sorted
1
2
3
4
6
return 1
algo
master
.
io
Step:
Start: gather all values, sort them, then scan adjacent gaps
0 / 11
Input
Example 1
Example 2
Example 3
Custom
tree
=
[4, 2, 6, 1, 3]
0 / 11
algo
master
.
io
Step:
Start: gather all values, sort them, then scan adjacent gaps