Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Construct BST from Preorder Traversal
Bookmark
Input
Example 1
Ascending
Descending
Custom
preorder
=
[8, 5, 1, 7, 10, 12]
Preorder Array
0
8
1
5
2
1
3
7
4
10
5
12
idx
Preorder Array
0
8
1
5
2
1
3
7
4
10
5
12
idx
Preorder Array
0
8
1
5
2
1
3
7
4
10
5
12
idx
8
5
BST
Preorder Array
0
8
1
5
2
1
3
7
4
10
5
12
idx
8
5
1
BST
Preorder Array
0
8
1
5
2
1
3
7
4
10
5
12
idx
8
5
1
BST
Preorder Array
0
8
1
5
2
1
3
7
4
10
5
12
idx
8
5
1
7
BST
Preorder Array
0
8
1
5
2
1
3
7
4
10
5
12
idx
8
5
1
7
BST
Preorder Array
0
8
1
5
2
1
3
7
4
10
5
12
idx
8
5
10
1
7
BST
Preorder Array
0
8
1
5
2
1
3
7
4
10
5
12
8
5
10
1
7
12
BST
Preorder Array
0
8
1
5
2
1
3
7
4
10
5
12
8
5
10
1
7
12
BST
Preorder Array
0
8
1
5
2
1
3
7
4
10
5
12
8
5
10
1
7
12
BST
algo
master
.
io
Step:
Start: Construct BST from preorder traversal
0 / 50
Input
Example 1
Ascending
Descending
Custom
preorder
=
[8, 5, 1, 7, 10, 12]
0 / 50
algo
master
.
io
Step:
Start: Construct BST from preorder traversal