Construct Binary Tree from Inorder and Postorder Traversal

Medium

Company Tags

You are given two integer arrays inorder and postorder where inorder is the inorder traversal of a binary tree and postorder is the postorder traversal of the same tree, construct and return the binary tree.

Example 1:

Input: inorder = [2,1,3,4], postorder = 

Output: [1,2,3,null,null,null,4]

Example 2:

Input: inorder = [1], postorder = [1]

Output: [1]

Constraints:

  • 1 <= postorder.length == inorder.length <= 3000.
  • -3000 <= inorder[i], postorder[i] <= 3000
  • inorder and postorder consist of unique values.
  • Each value of postorder also appears in inorder.
  • inorder is guaranteed to be the inorder traversal of the tree.
  • postorder is guaranteed to be the postorder traversal of the tree.


Company Tags

Please upgrade to NeetCode Pro to view company tags.

inorder =

postorder =