Example 4 : Construct BT from preorder and In-order Traversal

TopicDifficultyCompanies
Binary Tree
MEDIUM
Amazon
Google

Given preorder and inorder traversal of a tree, write a program to construct the binary tree using the preorder and inorder traversal.

Problem Note

  • You may assume that duplicates do not exist in the tree.

Example

Input:
preorder = [4, 7, 10, 15, 7]
inorder = [7, 4, 15, 10, 7]
Output: Return the following binary tree:
4
/ \
7 10
/ \
15 7

Code Editor

Practice and Learn

Best way to learn is through solving real problems. Practice this problem in this code editor.