105. Construct Binary Tree from Preorder and Inorder Traversal
Practice Construct Binary Tree from Preorder and Inorder Traversal for free on NudgeCode: Medium, Binary Tree pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
You get the preorder and the inorder traversal of the same binary tree. All values are distinct. Rebuild the tree and return its root.
Example
preorder = [3,9,20,15,7], inorder = [9,3,15,20,7] -> [3,9,20,null,null,15,7]
Constraints
- 1 <= preorder.length <= 3000
- inorder.length == preorder.length
- -3000 <= values <= 3000
- all values are unique
- both arrays describe the same tree