Flatten Binary Tree to Linked List

TopicDifficultyCompanies
Binary Tree
MEDIUM
Amazon
Microsoft
Yahoo
Adobe

Given a binary tree, write a program to flatten it to a linked list. The flattening of the binary tree should be in-place.

Problem Note

  • Note that the left child of all nodes should be NULL.

For example

Input: Given the following binary tree 
4
/ \
5 8
/ \ \
6 7 9
Output: The flattened tree should look like:
4
\
5
\
6
\
7
\
8
\
9

Code Editor

Practice and Learn

Best way to learn is through solving real problems. Practice this problem in this code editor.