Flatten multilevel list
A multilevel doubly linked list is given as a nested structure: a list of nodes where each node is [val, child] and child is either null (encoded as None / empty) — represented here as another nested list of the same shape, or [] for no child. Flatten it depth-first so a node's child sublist is spliced in right after that node and before the rest of the level. Return the flattened list of values in order.
Implement
flatten_multilevel(nodes: list) → list[int]Examples
in
[[[1,[]],[2,[[3,[]],[4,[]]]],[5,[]]]]out[1,2,3,4,5]What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 25 min
solution.py
InputExpectedGot
[[[1,[]],[2,[[3,[]],[4,[]]]],[5,[]]]][1,2,3,4,5]not run yetsample