Build Binary Tree from Preorder and Inorder Traversal

Try to solve the Build Binary Tree from Preorder and Inorder Traversal problem.

Statement

Create a binary tree from two integer arrays, pOrder and iOrder, where pOrder represents a preorder traversal of a binary tree, and iOrder represents an inorder traversal of the same tree.

Constraints:

  • 1≤1 \leq pOrder.length, iOrder.length ≤1000\leq1000
  • iOrder.length ==== pOrder.length
  • −1000≤-1000 \leq pOrder[i], iOrder[i] ≤1000\leq 1000
  • pOrder and iOrder consist of unique values.
  • Each value of iOrder also appears in pOrder and vice versa.

Examples

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy