The Flatten Binary Tree to Linked List interview question asks you to take a binary tree and reorganize it into a "linked list" structure in-place. The resulting structure should still use the TreeNode class, where all left pointers are null, and the right pointers form a sequence that matches the Pre-order Traversal of the original tree.
Companies like Meta, Amazon, and Microsoft use this to test a candidate's mastery of Binary Tree interview patterns. It evaluations whether you can manipulate pointers to change the shape of a tree while preserving a specific traversal order. It also tests your ability to solve a structural transformation problem with extra space.
There are two main approaches:
prev pointer to the node processed in the previous step and set root.right = prev.right pointer to the current node's right child.right and set left to null.right node.Tree: 1 is root, 2 is left child, 5 is right child. 2 has children 3, 4.
2-3-4.null.1 -> 2 -> 3, 2.right -> 4, 4.right -> 5.Practice "Morris Traversal" concepts. The idea of "stitching" the right subtree to a predecessor in the left subtree is a powerful technique for tree problems requiring space. This is a core Tree interview pattern.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Linked List in Binary Tree | Medium | Solve | |
| Binary Tree Preorder Traversal | Easy | Solve | |
| Binary Tree Inorder Traversal | Easy | Solve | |
| Binary Tree Postorder Traversal | Easy | Solve | |
| Convert Binary Search Tree to Sorted Doubly Linked List | Medium | Solve |