Flatten Multi-Level Linked List

You are given a multilevel doubly linked list where each node has a next pointer, a prev pointer, and a child pointer. Each node has at most one child. Flattening walks depth first: the entire child list of a node appears immediately after that node, then the remaining same level nodes follow after every nested level. Node identities are preserved: the same node objects are rewired in place, every child pointer ends up null, and every prev pointer agrees with the flattened next chain.

The runner uses the version 1 node graph transport: it builds real node objects with val, next, prev, and child, invokes solve(head), and observes the resulting flattened chain by node identity. The expected value is the final value sequence, while the trusted validator also checks depth-first preorder node identities, prev links, and that every child becomes null.

Examples
Input: {"nodes":[],"roots":{"head":null}}
Output: []
Hints

Flatten Multi-Level Linked List

You are given a multilevel doubly linked list where each node has a `next` pointer, a `prev` pointer, and a `child` pointer. Each node has at most one child. Flattening walks depth first: the entire child list of a node appears immediately after that node, then the remaining same level nodes follow after every nested level. Node identities are preserved: the same node objects are rewired in place, every `child` pointer ends up null, and every `prev` pointer agrees with the flattened `next` chain.