Construct Binary Tree from Inorder and Postorder Traversal
MediumTrees
Decode it first. Clues, constraints, pattern and plan before any code.You are given two lists that describe the same binary tree: inorder (left subtree, then the node, then the right subtree) and postorder (left subtree, then the right subtree, then the node). All values are unique. Rebuild the tree and return its root.
Trees in the examples are written in level order (top to bottom, left to right), with null for a missing child, the same way the tests build them.
inorder = [4, 2, 5, 1, 3], postorder = [4, 5, 2, 3, 1] → [1, 2, 3, 4, 5]
inorder = [1, 2, 3], postorder = [3, 2, 1] → [1, null, 2, null, 3]
inorder = [7], postorder = [7] → [7]Constraints
1 <= inorder.length <= 3000postorder.length == inorder.length-3000 <= inorder[i], postorder[i] <= 3000- Both lists describe the same tree.