Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Construct Binary Tree from Preorder and Inorder Traversal

XPChallenge Points: 20
levelLevel: Medium

You are given two lists of integers:


• preorder → the preorder traversal of a binary tree
• inorder → the inorder traversal of the same tree
Your task is to construct the original binary tree from these two lists and return its root.
Reminder:
• Preorder traversal: Root → Left → Right
• Inorder traversal: Left → Root → Right

Example 1:

Input: preorder = [7,4,9,12,15] inorder = [9,4,12,7,15]

Output: [7,4,null,9,12,null,15]

Explanation:

Construct the tree that matches these traversals.

Example 2:

Input: preorder = [5] inorder = [5]

Output: [5]

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result