Preorder gives root-first order; inorder splits left/right subtrees around the root.
Use a hash map from value to its inorder index. Walk preorder with a pointer pre_i. Recursively build subtrees from inorder ranges.
Each root chosen from preorder partitions the inorder range into exact left and right subtree elements.
Preorder gives root-first order; inorder splits left/right subtrees around the root.
Use a hash map from value to its inorder index. Walk preorder with a pointer pre_i. Recursively build subtrees from inorder ranges.
Each root chosen from preorder partitions the inorder range into exact left and right subtree elements.