← All problems

Construct Tree from Preorder and Inorder

Medium treesrecursionhash maps LeetCode ↗
Rebuild a binary tree from its preorder and inorder traversals.

Hints (0/3 revealed)

Log in to reveal hints progressively.

Complexity

Time O(n), Space O(n)

Common pitfalls

  • Slicing arrays each call (O(n^2))
  • Linear search for root in inorder

Your solution

Log in to save your code and track progress.