Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Trim a Binary Search Tree
Bookmark
Recursive DFS
Iterative
Input
Trim Easy
Trim [1,3]
Simple Trim
Trim Left
Trim Right
Custom
tree
=
[1, 0, 2, -1]
,
low
=
1
,
high
=
2
Range: [1, 2]
1
0
2
-1
Kept
Current
Checking
Removed
Range: [1, 2]
1
0
2
-1
Kept
Current
Checking
Removed
Range: [1, 2]
1
0
2
-1
node
Call Stack
trimBST(1)
Kept
Current
Checking
Removed
Range: [1, 2]
1
0
2
-1
node
Call Stack
trimBST(0)
trimBST(1)
Kept
Current
Checking
Removed
Range: [1, 2]
1
0
2
-1
node
Call Stack
trimBST(0)
trimBST(1)
Kept
Current
Checking
Removed
Range: [1, 2]
1
2
node
Call Stack
trimBST(1)
Kept
Current
Checking
Removed
Range: [1, 2]
1
2
Call Stack
trimBST(null)
trimBST(2)
trimBST(1)
Kept
Current
Checking
Removed
Range: [1, 2]
1
2
node
Call Stack
trimBST(2)
trimBST(1)
Kept
Current
Checking
Removed
Range: [1, 2]
1
2
node
Call Stack
trimBST(2)
trimBST(1)
Kept
Current
Checking
Removed
Range: [1, 2]
1
2
node
Call Stack
trimBST(1)
Kept
Current
Checking
Removed
Range: [1, 2]
1
2
Call Stack
empty
Kept
Current
Checking
Removed
algo
master
.
io
Step:
Start: trim the BST to [1, 2]
0 / 19
Input
Trim Easy
Trim [1,3]
Simple Trim
Trim Left
Trim Right
Custom
tree
=
[1, 0, 2, -1]
,
low
=
1
,
high
=
2
0 / 19
algo
master
.
io
Step:
Start: trim the BST to [1, 2]