Facebook Pixel

Reconstruct Binary Tree from Preorder and Inorder Traversal

Given two arrays representing the preorder and inorder traversals of the same binary tree with unique values, reconstruct the original tree.

Input: preorder = [3,9,20,15,7], inorder = [9,3,15,20,7].

Output: The binary tree structure:

Construct Binary Tree from Preorder and Inorder Traversal

Try it yourself

Solution

Invest in Yourself
Your new job is waiting. 83% of people that complete the program get a job offer. Unlock unlimited access to all content and features.
Go Pro