Product
Pricing
Blog
Forum
NEW
Referral
Description
Solution
Discussion
Submissions
Ask AI
AI Insights
Quick Summary
Reconstruct a tree structure from a flat list where each element defines a node and references its children by array index.
Identify the unique root by tracking which node index never appears as a child reference.
Execute an iterative preorder traversal to output node key-value pairs in the specified visitation order.
What This Tests
Tree reconstruction from adjacency-style arrays
Root detection using index tracking or set operations
Iterative depth-first traversal implementation
Array indexing and state management without explicit object graphs
Common Patterns
Graph Traversal
DFS/BFS
Hashing
Collapse
Hint 1
Hint 2
Hint 3
What Interviewers May Ask Next
Report
Report seen similar question in interview
Ask AI Assistant
Ask AI Assistant
Ask me anything about this coding question!
python
Auto
Debug
Run
Submit
Test Cases
Input
Output
Expected