Deep Copy a Random-Pointer List
Reported by candidates from Superhuman's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Superhuman reported this one in July 2026, and it looks friendlier than it is. It's the classic random-pointer list copy wrapped in an index-encoded format, plus a twist: mutate the original after copying and prove the copy didn't move. If you've got an OA invite, expect to spend your time on the independence part, not the copying. The pattern is a hash map from original node to clone, or just index arrays. StealthCoder is there as a safety net if you blank during the live assessment, but the trick is small enough to learn tonight.
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. 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
Here's the trick. The input is already encoded as indices, so you don't need real node objects at all. A deep copy of the encoded list is just a fresh copy of every row. Build the copy with new inner arrays, not a shallow reference to the same rows. Then apply the mutation to the original only: set nodes[mutationIndex] to [newValue, newRandomIndex]. The edge case that breaks naive solutions is aliasing. If you reuse the same inner arrays in both snapshots, the mutation shows up in both and your copy fails Example 1. Also watch -1 for null random pointers, and the single-node self-pointer case in Example 3. If you build real nodes, use a hash map from original to clone in two passes, one to create and one to wire next and random. StealthCoder is the hedge if you freeze on the output shape, which is a list of two snapshots, original first.
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 Superhuman's OA.
Superhuman 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
What's the trick in the Superhuman deep copy random-pointer problem?+
Independence. The copy must share no structure with the original. Clone every row into a new array, or use a map from original node to clone. Then mutate only the original. If both snapshots share inner arrays, the mutation leaks into the copy and you fail.
How hard is this OA question really?+
Easy to medium. The standard random-pointer copy is a known medium. The index encoding makes it simpler, and the mutation step only adds a check that you didn't alias. Most failures come from shallow copies, not from the algorithm.
Do I need to build real linked list nodes?+
No. The input is index-based, so you can work on the arrays directly. Copy each [value, randomIndex] pair into a new array, mutate the original row, and return both. Building nodes with a hash map works too, but it's extra code with more room for bugs.
Which edge cases should I test before submitting?+
Test a single node with a self-pointing random, as in Example 3. Test a random of -1 turning into a valid index and the reverse. Test mutating the last node. Test that changing the original leaves the copy's values and random indexes untouched.
How do I prepare for this in 48 hours?+
Write the classic copy-list-with-random-pointer solution twice, once with a hash map and once with interleaved nodes. Then practice returning two snapshots from one function. Focus on deep versus shallow copies. That's the whole skill this question checks.