Coding Challenge

Construct Binary Tree from Preorder and Inorder Traversal

Medium
treedfs

Reconstruct a binary tree from preorder and inorder traversals.

Given preorder and inorder traversal arrays with unique values, rebuild and return the binary tree.

Examples

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

Output: tree rooted at 3

Constraints

  • All values are unique

Preparing your coding workspace...