FDEInterviews logoFDE/Interviews
Coding & DSA / 84
mediumAmazonMicrosoftGoogle

Construct a binary tree from its preorder and inorder traversals

The clean answer hinges on one insight: preorder names the root, inorder splits left from right. The trap is the O(n squared) version that slices arrays and scans for the root; the O(n) version uses a hashmap of inorder indices and passes bounds instead.

Updated Aug 2026 · Grounded in real Forward Deployed Engineer interview loops and written to a senior-engineer editorial bar.

The clean answer hinges on one insight: preorder names the root, inorder splits left from right. The trap is the O(n squared) version that slices arrays and scans for the root; the O(n) version uses a hashmap of inorder indices and passes bounds instead.

Unlock the other 466 answers · ₹2,000 / $25Your progress and mastery stay saved · 6 months · one payment · no auto-renew
UP NEXT ON YOUR JOURNEY
FEDITOR'S NOTE

What separates the pass from the stall is whether you reach for the inorder index map without prompting. Candidates who slice subarrays on every call write correct but quadratic code, and the interviewer is waiting to ask 'what's the complexity?' to see if you notice. The duplicate-values caveat is the reserved follow-up: with repeated values you can't uniquely locate the root in inorder, so the reconstruction is ambiguous.

DISCUSSION · 0

No comments yet — be the first to share your approach.