Deep Copy a Random-Pointer 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 October 2025, and n tops out at 10^4, so the real question isn't speed, it's whether your copy is truly independent. It's the classic random-pointer list deep copy with a mutation twist bolted on. You copy, then change the original at one index, then return both snapshots. If your copy shares a single node with the original, the mutation leaks and the second snapshot is wrong. The follow-up asks for O(1) extra space. If you blank on the interleaving trick during the live OA, StealthCoder is the safety net running invisibly on your screen.
The problem
A linked list has n nodes in next-pointer order. Each node contains an integer value and a random pointer that may target any node or be null. The list is encoded by nodes, where nodes[i] = [value, randomIndex]. The next pointer of node i targets node i + 1, except for the last node. A randomIndex of -1 means null. Create a deep copy whose next and random pointers target only copied nodes. For this exercise, after copying, mutate the original node at mutationIndex: set its value to newValue and its random pointer to newRandomIndex. Return two encoded snapshots in order: the mutated original list, then the unchanged deep copy. Follow-up: in the pointer-node model, perform the deep copy with O(1) auxiliary space beyond the copied nodes and returned snapshots. You may interleave copied nodes with originals temporarily, but restore the original next-pointer chain before returning. Function copyAndMutateRandomList(nodes: int[][], mutationIndex: int, newValue: int, newRandomIndex: int) → int[][][] Examples Example 1 nodes = [[7,-1],[13,0],[11,4],[10,2],[1,0]] mutationIndex = 1 newValue = 130 newRandomIndex = 4 return = [[[7,-1],[130,4],[11,4],[10,2],[1,0]],[[7,-1],[13,0],[11,4],[10,2],[1,0]]] The second original node changes to [130,4]. The second copied node remains [13,0], so the copy is independent. Example 2 nodes = [[1,1],[2,1]] mutationIndex = 0 newValue = 10 newRandomIndex = -1 return = [[[10,-1],[2,1]],[[1,1],[2,1]]] The first original node loses its random pointer. The copy retains both original random references. Example 3 nodes = [[5,0]] mutationIndex = 0 newValue = 6 newRandomIndex = -1 return = [[[6,-1]],[[5,0]]] The one-node copy keeps its self-random pointer even after the original is changed. Constraints 1 <= nodes.length <= 10^4. Every row of nodes contains exactly two integers. -10^9 <= nodes[i][0], newValue <= 10^9. Every random index and newRandomIndex is -1 or an index from 0 through nodes.length - 1. 0 <= mutationIndex < nodes.length.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The core is a two-pass copy. The easy way: pass one creates a copy node for every original and stores it in a map keyed by original node (or just an array by index, since the input is index-encoded). Pass two wires next and random through the map. The O(1) follow-up interleaves: insert each copy right after its original, set copy.random = original.random.next, then split the lists and restore the original next chain. The pitfall is a null random, where you must not dereference it. The second pitfall is mutating before the copy is fully separated. Apply the mutation only after the lists are split and restored. Then encode each list back to [value, randomIndex] by mapping nodes to indices. Check Example 3, a one-node self-pointer, since it breaks sloppy null handling. If the interleave logic slips under pressure, StealthCoder is the hedge that hands you a clean version live.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Deep Copy a Random-Pointer 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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as copy list with random pointer. 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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Deep Copy a Random-Pointer List FAQ
How hard is this Bloomberg OA question really?+
It's medium. The copy itself is a well-known pattern. The extra work is decoding the index-based input into nodes, applying the mutation after the copy, and encoding both lists back. Most mistakes come from that glue code, not from the copy algorithm.
What's the trick to the deep copy?+
Map each original node to its copy, then wire next and random in a second pass. Doing it in two passes avoids the forward-reference problem where a random pointer targets a node you haven't created yet.
Do I need the O(1) space follow-up?+
Write the hash map or array version first so you have a correct answer. The interleaving approach is the follow-up, so attempt it only if the basic version passes. You must restore the original next chain before returning, or the snapshots break.
What edge cases should I test?+
Test a single node with a self-random pointer, random set to -1, and a mutation that changes the random pointer to null or to the last index. Also confirm the copy snapshot stays unchanged after the original mutates.
How do I prepare in 48 hours?+
Hand-write the linked list random copy until the interleave and split steps feel automatic. Then practice encoding and decoding lists to index arrays, since that conversion is where this variant differs from the standard version.