Construct Binary Tree from Preorder and Inorder Traversal
MediumLeetCodeBinary Trees
Approach hintTry it first, then revealHide
The next preorder value is the root of the current subtree, and its position in the inorder array separates the left and right subtrees. A hash map from value to inorder index makes this O(n).