Flatten a Multilevel Singly Linked List
Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Bloomberg reportedly served this one in November 2025, and it all comes down to the linked list. You get arrays standing in for pointers: values, next, child, and a head index. Flatten the multilevel list in preorder, splicing each child list between its parent and the parent's old next. The catch is the O(1) pointer state, so no stack, no recursion. This is the singly linked cousin of a classic, and it's easy to overthink under a clock. If you blank mid-assessment, StealthCoder runs invisibly as a safety net. Know the trick first and you probably won't need it.
The problem
Node i has value values[i], next index next[i], and child index child[i]; -1 means null. Starting at head, flatten the multilevel singly linked list in depth-first preorder by splicing every child list between its parent and the parent's original next continuation. Return flattened values. Use O(1) auxiliary pointer state, excluding the returned array. Function flattenMultilevelSingly(values: int[], next: int[], child: int[], head: int) → int[] Examples Example 1 values = [1,2,3,4,5] next = [1,2,-1,4,-1] child = [-1,3,-1,-1,-1] head = 0 return = [1,2,4,5,3] Node 2's child list 4,5 is spliced before node 3. Constraints The pointer structure is finite and contains each reachable node once. All nonnegative indices are valid.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is to walk the list with one cursor and splice as you go. At each node with a child, find the tail of the child list by walking until next is -1. Point that tail's next at the current node's original next. Then set the current node's next to the child and clear its child to -1. Advance the cursor and keep going. Nested children get handled naturally because the spliced list is walked later, and its own children get spliced when you reach them. That keeps the extra state at a couple of integers. The common pitfall is losing the original next before you rewire it, or forgetting to clear child, which causes duplicates or loops. Also handle head = -1 and a child list with no tail issues. Since you mutate the arrays, collect values while traversing. If the tail-finding logic goes fuzzy live, StealthCoder is the hedge that gets you unstuck.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Flatten a Multilevel Singly Linked List cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as flatten a multilevel doubly linked list. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Bloomberg's OA.
Bloomberg reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Flatten a Multilevel Singly Linked List FAQ
What's the trick to Flatten a Multilevel Singly Linked List?+
Use a single cursor. When the current node has a child, find the child list's tail, link that tail to the current node's original next, then make the child the new next and clear the child. Move forward and repeat. No stack needed.
How do I meet the O(1) pointer state requirement?+
Don't recurse and don't keep a stack. Rewire the next and child arrays in place using a cursor and a temporary tail pointer. The returned array of values is excluded from the space count, so appending to it as you walk is fine.
Is this the same as the LeetCode doubly linked version?+
It's very close in spirit. The LeetCode version is doubly linked and needs prev pointers fixed. Here there's no prev, so you only rewire next and child. The splice logic and preorder order are the same idea.
What edge cases break most solutions?+
Head equal to -1, a child list that itself has children, and forgetting to clear child after splicing. Also save the original next before overwriting it, or you lose the rest of the list. Check the example where node 2's child goes before node 3.
How do I prepare in 48 hours for a linked list OA like this?+
Practice pointer rewiring on paper with the index arrays. Trace the given example by hand until splicing feels automatic. Then code it once from scratch without a stack. Focus on tail-finding and saving next before rewriting. Two or three clean runs beat grinding many problems.