← Questions

Flatten a linked list with side branches into one doubly linked list

0
TeslaCodingLast asked Sep 2026

Each node of a singly linked list has a forward link and may also have one side branch: a link to the head of another list, whose nodes may have side branches of their own. Flatten the whole structure into a single doubly linked list, with each branch spliced in right after the node it hangs from, and set every node's back link. Do it in place and discuss recursion depth versus an iterative approach.

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding