shlogg · Early preview
Md Ariful Haque @mah-shamim

Construct Binary Tree From Preorder And Postorder Traversal

Construct binary tree from preorder and postorder traversal using recursion. Identify root as first element in preorder, split arrays based on left child position in postorder, and recursively construct left and right subtrees.

889. Construct Binary Tree from Preorder and Postorder Traversal
Difficulty: Medium
Topics: Array, Hash Table, Divide and Conquer, Tree, Binary Tree
Given two integer arrays, preorder and postorder where preorder is the preorder traversal of a binary tree of distinct values and postorder is the postorder traversal of the same tree, reconstruct and return the binary tree.
If there exist multiple answers, you can return any of them.
Example 1:


Input: preorder = [1,2,4,5,3,6,7], postorder = [4,5,2,6,7,3,1]
Output: [1,2,3,4,5,6,7]

Example 2:

Input: preorder = [1], postorder = [1]
Output: [1]...