Example
Input
[1, 2, 5, 3, 4, None, 6]
Output
[1, 2, 3, 4, 5, 6]
Original tree (level-order): [1,2,5,3,4,None,6]. Preorder traversal is [1,2,3,4,5,6]. After flattening, the tree becomes a right-skewed list 1 -> 2 -> 3 -> 4 -> 5 -> 6.
Full lesson preview
Transform a binary tree into a right-skewed linked list in-place following preorder traversal.
Problem statement
Task
Examples
Input
[1, 2, 5, 3, 4, None, 6]
Output
[1, 2, 3, 4, 5, 6]
Original tree (level-order): [1,2,5,3,4,None,6]. Preorder traversal is [1,2,3,4,5,6]. After flattening, the tree becomes a right-skewed list 1 -> 2 -> 3 -> 4 -> 5 -> 6.
Input format
Output format
Constraints
Samples
Input
[1, 2, 5, 3, 4, None, 6]
Output
[1, 2, 3, 4, 5, 6]
See example above. The flattened list follows preorder traversal.