The problem. You're given a doubly linked list whose nodes also have a child pointer. A child pointer, when it isn't null, leads to a separate doubly linked list — a lower level — whose nodes may have children of their own. Flatten the structure into one doubly linked list: each child level goes right after its parent node, before the parent's old next. Set every child to null and return the head.
1 - 2 - 3 - 4 - 5 - 6
|
7 - 8 - 9 - 10
|
11 - 12
-> 1 2 3 7 8 11 12 9 10 4 5 6Members only · free account
The rest of this lesson, with 7 more sections, 1 drawing, a dry-run simulator and code in JavaScript, Python, Java and C++, opens with a free account.
Not ready yet? The Arrays course is free to read, no account needed.
In the rest of this lesson