arrow_back Back to Challenges

#105 Construct Binary Tree from Preorder and Inorder Traversal

Medium Acceptance 0%
description

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 of the same tree, construct and return the binary tree.

checklist Constraints

1 <= preorder.length <= 3000
inorder.length == preorder.length
-3000 <= preorder[i], inorder[i] <= 3000
All the values of preorder and inorder are unique.

science Examples

Case #1

In: preorder = [3,9,20,15,7] inorder = [9,3,15,20,7]
Out: [3,9,20,null,null,15,7]

Case #2

In: preorder = [-1] inorder = [-1]
Out: [-1]

Mastery Tags

Hash Table Recursion Trees

Hiring Companies

Amazon Google Microsoft
code

Integrated IDE

code_blocks
Coding
psychology
Aptitude