Flatten a Multilevel Singly Linked List
Updated
Problem statement
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 = 0return = [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.
More Bloomberg LP Phone Screen questions
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
- Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
- Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Sparse Vector and Matrix OperationsPHONE SCREEN · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- BST to Sorted Circular Doubly Linked ListGoogle · ONSITE INTERVIEWGoogle interview questions
- Flatten a Branched List into a Doubly Linked ListTesla · PHONE SCREENTesla interview questions
- BST to Sorted Circular Doubly Linked ListApple · ONSITE INTERVIEWApple interview questions
- Turn a BST Into a Sorted Doubly Linked ListAdobe · PHONE SCREENAdobe interview questions
- Convert a Binary Tree to a Doubly Linked ListExpedia · ONSITE INTERVIEWExpedia interview questions
- Convert a BST to a Doubly Linked ListMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- LRU Cache for Query ResultsAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Feature Flags with Rules, Dependencies and ExposurePerplexity AI · ONSITE INTERVIEWPerplexity AI interview questions
- LRU CacheServiceNow · PHONE SCREEN · ONSITE INTERVIEWServiceNow interview questions
- Number of IslandsIntuit · ONSITE INTERVIEWIntuit interview questions
Interview reports that mention this question
Bloomberg LP interview experiences
- Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
- Bloomberg Interview Questions, Level Not Reported: 65 Questions
- Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
- Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)
- Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)