Flatten Binary Tree to Linked List
Understand and solve the interview question "Flatten Binary Tree to Linked List".
We'll cover the following
Description
We are given the root of a binary tree. We have to flatten the tree into a linked list. The left child of the linked list is always null, and the right child points to the next node in the list. The nodes in the linked list should be in the same order as the pre-order traversal of the given binary tree.
Constraints
- -100 <= ‘Node.val’ <= 100
- The tree contains nodes in the range [0, 2000].
Let’s see how a flattened tree looks like in the illustration below:
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.