Description
You have a multilevel doubly linked list where nodes may have a child pointer leading to a separate doubly linked list. Flatten all lists into a single level. Return the result as an array.
Examples
head with child pointersflattened listDFS to flatten children between current and next.
[1,2,null,3,null,4,5][1,3,4,5,2]The first node (1) has a child pointer to node 3. Flattening inserts the child subtree (3->4->5) between node 1 and its original next node 2. This demonstrates the basic flattening operation where a child list is spliced into the main list.
[10,20,30,null,40,null,null,50,60][10,40,50,60,20,30]Node 10 has a child pointer to node 40, and node 40 has a child pointer to node 50. This shows nested children where it is necessary to recursively flatten multiple levels. Processing 10's child (40) first, then 40's child (50->60), creating a depth-first traversal through the multilevel structure.
Constraints
- •
Number of nodes ≤ 1000 - •
1 ≤ Node.val ≤ 10⁵