loading

Construct Binary Tree from Inorder and Postorder Traversal — Step-by-Step Visualization

mediumLeetCode #106ArrayHash TableDivide and ConquerTreeBinary Tree

Given two integer arrays inorder and postorder where inorder is the inorder traversal and postorder is the postorder traversal of the same tree, construct and return the binary tree.

Algorithm Pattern

Divide and Conquer

Key Idea

Last element of postorder is root. Its position in inorder splits left and right subtrees.

Step-by-Step Approach

  1. Last element of postorder = root
  2. Find root in inorder to get left/right subtree sizes
  3. Recurse on left and right portions of both arrays

Related Problems