Construct Binary Tree from Preorder and Inorder Problem

Construct Binary Tree from Preorder and Inorder Problem — ExecCode Medium DSA Practice

Solve the Construct Binary Tree from Preorder and Inorder problem on ExecCode. Free online medium DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Given two integer arrays preorder and inorder where preorder is the preorder traversal of a binary tree and inorder is the inorder traversal, construct and return the binary tree.

Examples

Input preorder = [3, 9, 20, 15, 7], inorder = [9, 3, 15, 20, 7]; Output [3, 9, 20, null, null, 15, 7]

Constraints

1 ≤ n ≤ 3000 preorder and inorder consist of unique values

Practice Construct Binary Tree from Preorder and Inorder free on ExecCode. Browse DSA problems, topic map, and placement guides.