ByteByteGo logo
menuProblems List

Flatten a Multi-Level Linked List

Medium

In a multi-level linked list, each node has a next pointer and child pointer. The next pointer connects to the subsequent node in the same linked list, while the child pointer points to the head of a new linked list under it. This creates multiple levels of linked lists. If a node does not have a child list, its child attribute is set to null.

Flatten the multi-level linked list into a single-level linked list by linking the end of each level to the start of the next one.

Example:

How the custom test cases work

The input is a nested list representation of a multi-level linked list. Each element in the list represents a node which includes a value and a child list, with the entire data structure using the following structure:

[[val_1, [child_list_1]], [val_2, [child_list_2]], ...]

Each child list follows this same structure.

You can practice coding exercises online by logging into bytebytego.com on your laptop.