←ENG-DSA-073UI Component Tree Reconstruction
00:00
🐍 Python Idle
Mode:Web

UI Component Tree Reconstruction

CompaniesMeta, Vercel
Est. Time~50 min
LevelSenior
TreesRecursionArrays
🚨 P0 Incident
MetaVercel

React's Virtual DOM represents the UI as a tree. During server-side rendering (SSR) hydration, the client receives serialized flat arrays of components. To rebuild the exact component hierarchy in memory, the hydration engine processes preorder (root first) and inorder (left, root, right) traversal logs.

πŸ“₯ Assigned to:You β€” Senior Engineer
Your Task

Given two integer arrays `preorder` and `inorder` where `preorder` is the preorder traversal of a binary tree and `inorder` is the inorder traversal of the same tree, construct and return the binary tree.

⏱ Time: O(N)πŸ’Ύ Space: O(N)
Example 1
Input:Β Β pre=[3,9,20,15,7], in=[9,3,15,20,7]
Output:Β Root=3, L=9, R=20(L15, R7)
Example 2
Input:Β Β pre=[-1], in=[-1]
Output:Β Root=-1
πŸ”’ +3 hidden test cases β€” revealed on Submit
Hints
Loading editor…
Test Output
β–Ά Run Code to test against examples Β· Submit to judge all 5 test cases
EngPrep β€” Real Engineering. Real Interviews.