Bird
Raised Fist0

Given the final flattened linked list sequence [1, 2, 3, 4, 5, 6] obtained by the optimal flatten algorithm, which of the following was the original binary tree structure?

hard🔄 Reverse Engineer Q9 of Q15
Tree: Depth-First Search - Flatten Binary Tree to Linked List
Given the final flattened linked list sequence [1, 2, 3, 4, 5, 6] obtained by the optimal flatten algorithm, which of the following was the original binary tree structure?
AA skewed tree with all nodes as right children
BA tree with root 1 and only right children 2,3,4,5,6
CA tree with root 1 and only left children 2,3,4,5,6
DA balanced tree with root 1, left subtree (2,3,4), right subtree (5,6)
Step-by-Step Solution
Solution:
  1. Step 1: Analyze preorder sequence

    Sequence 1,2,3,4,5,6 suggests root 1, left subtree nodes 2,3,4, right subtree nodes 5,6.
  2. Step 2: Match to tree structure

    Balanced tree with root 1, left subtree (2,3,4), right subtree (5,6) matches this preorder.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    Preorder sequence matches balanced tree structure [OK]
Quick Trick: Preorder sequence reveals original tree shape [OK]
Common Mistakes:
MISTAKES
  • Assuming skewed tree from linear list
  • Ignoring subtree grouping in preorder
Trap Explanation:
PITFALL
  • Candidates often mistake linear list for skewed tree ignoring subtree structure.
Interviewer Note:
CONTEXT
  • Tests ability to reason backwards from output to input tree.
Master "Flatten Binary Tree to Linked List" in Tree: Depth-First Search

3 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Tree: Depth-First Search Quizzes