Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Minimum Absolute Difference in BST
Bookmark
Inorder Array
Prev Pointer
Morris
Input
Standard (minDiff=1)
Mixed (minDiff=1)
Balanced (minDiff=2)
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
1
gather
1
onto the strip
4
2
6
1
3
minDiff = ∞
values
1
2
gather
2
onto the strip
4
2
6
1
3
minDiff = ∞
values
1
2
3
4
gather
4
onto the strip
4
2
6
1
3
minDiff = ∞
values
1
2
3
4
6
gather
6
onto the strip
4
2
6
1
3
minDiff = ∞
values
1
2
3
4
6
inorder already ascending → scan adjacent pairs
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: inorder of a BST lists values in ascending order
0 / 11
Input
Standard (minDiff=1)
Mixed (minDiff=1)
Balanced (minDiff=2)
Custom
tree
=
[4, 2, 6, 1, 3]
0 / 11
algo
master
.
io
Step:
Start: inorder of a BST lists values in ascending order