Skip to content
We areTOP 1%

Construct Binary Tree from Preorder and Inorder Traversal

MediumLeetCodeBinary Trees
Solve on LeetCode(opens in a new tab)
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews
Approach hintTry it first, then reveal

The next preorder value is the root of the current subtree, and its position in the inorder array separates the left and right subtrees. A hash map from value to inorder index makes this O(n).

More in Binary Trees

Binary Trees questions
#ProblemPlatformDifficultyOpen1st1st Visit2nd2nd VisitRevRevise
1Binary Tree Inorder TraversalLeetCodeEasy Solve Binary Tree Inorder Traversal on LeetCode (opens in a new tab)
2Maximum Depth of Binary TreeLeetCodeEasy Solve Maximum Depth of Binary Tree on LeetCode (opens in a new tab)
3Invert Binary TreeLeetCodeEasy Solve Invert Binary Tree on LeetCode (opens in a new tab)
4Symmetric TreeLeetCodeEasy Solve Symmetric Tree on LeetCode (opens in a new tab)
5Balanced Binary TreeLeetCodeEasy Solve Balanced Binary Tree on LeetCode (opens in a new tab)
6Diameter of Binary TreeLeetCodeEasy Solve Diameter of Binary Tree on LeetCode (opens in a new tab)
7Permutation TransformationCodeforcesEasy 1200Solve Permutation Transformation on Codeforces (opens in a new tab)
8Apple TreeCodeforcesEasy 1200Solve Apple Tree on Codeforces (opens in a new tab)
9Binary Tree Level Order TraversalLeetCodeMedium Solve Binary Tree Level Order Traversal on LeetCode (opens in a new tab)
10Binary Tree Zigzag Level Order TraversalLeetCodeMedium Solve Binary Tree Zigzag Level Order Traversal on LeetCode (opens in a new tab)
11Count Good Nodes in Binary TreeLeetCodeMedium Solve Count Good Nodes in Binary Tree on LeetCode (opens in a new tab)
12Path Sum IILeetCodeMedium Solve Path Sum II on LeetCode (opens in a new tab)
13Anji's Binary TreeCodeforcesMedium 1300Solve Anji's Binary Tree on Codeforces (opens in a new tab)
14Masha and a Beautiful TreeCodeforcesMedium 1300Solve Masha and a Beautiful Tree on Codeforces (opens in a new tab)
15Construct Binary Tree from Preorder and Inorder TraversalLeetCodeMedium Solve Construct Binary Tree from Preorder and Inorder Traversal on LeetCode (opens in a new tab)
16Flatten Binary Tree to Linked ListLeetCodeMedium Solve Flatten Binary Tree to Linked List on LeetCode (opens in a new tab)
17Maximum Width of Binary TreeLeetCodeMedium Solve Maximum Width of Binary Tree on LeetCode (opens in a new tab)
18All Nodes Distance K in Binary TreeLeetCodeMedium Solve All Nodes Distance K in Binary Tree on LeetCode (opens in a new tab)
19Cut 'em all!CodeforcesMedium 1500Solve Cut 'em all! on Codeforces (opens in a new tab)
20Vertical Order Traversal of a Binary TreeLeetCodeHard Solve Vertical Order Traversal of a Binary Tree on LeetCode (opens in a new tab)

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account