GO TO A SECTION

↑ ↓ to navigate · Enter to openExplore all sections →
FDEInterviews logo
← 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.

20 answers per topic instead of 10, plus saved progress and bookmarks · no cardor unlock all 559 remaining answers · ₹2,000 / $25

Every answer, concept and course, every paper breakdown, all published video lessons, hands-on FDE Lab missions, Premium PDF guides and companion files, the full practice-test bank and work-sample downloads. Referral Premium excludes guide PDFs and their companion files.

6 months · One payment · No auto-renewal

Study alongside free video lessons.

Keep practising

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.