Learn
Practice
Newsletter
Resources
Mobile
New
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Convert Sorted Array to Binary Search Tree
Bookmark
Input
Example 1
Complete BST
Nine Elements
Custom
nums
=
[-10, -3, 0, 5, 9]
nums
-10
0
-3
1
0
2
5
3
9
4
mid becomes the root, halves become
subtrees
nums
-10
0
-3
1
0
2
5
3
9
4
mid becomes the root, halves become
subtrees
nums
-10
0
-3
1
0
2
5
3
9
4
0
node.left = helper(
0, 1
)
nums
-10
0
-3
1
0
2
5
3
9
4
0
-10
node.left = helper(
0, -1
)
nums
-10
0
-3
1
0
2
5
3
9
4
0
-10
-3
node = TreeNode(
-3
)
nums
-10
0
-3
1
0
2
5
3
9
4
0
-10
-3
[2..1]
is empty: return null
nums
-10
0
-3
1
0
2
5
3
9
4
0
-10
-3
node.right = helper(
3, 4
)
nums
-10
0
-3
1
0
2
5
3
9
4
0
-10
5
-3
[3..2]
is empty: return null
nums
-10
0
-3
1
0
2
5
3
9
4
0
-10
5
-3
9
node.left = helper(
4, 3
)
nums
-10
0
-3
1
0
2
5
3
9
4
0
-10
5
-3
9
[5..4]
is empty: return null
nums
-10
0
-3
1
0
2
5
3
9
4
0
-10
5
-3
9
return root
algo
master
.
io
Step:
Start: build a height-balanced BST from the sorted array
0 / 33
Input
Example 1
Complete BST
Nine Elements
Custom
nums
=
[-10, -3, 0, 5, 9]
0 / 33
algo
master
.
io
Step:
Start: build a height-balanced BST from the sorted array