Copy a Doubly Linked List with a Special Pointer
Reported by candidates from Microsoft's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks a first attempt on this Microsoft OA, reported in October 2026, is copying the nodes and then pointing the clone's special pointer back at the original list. Then the mutation leaks into your "deep copy" and the snapshot comes out wrong. This is a linked-list problem dressed up as a clone-with-random-pointer task, with an encode step on the end. You've got an index array in, two encoded snapshots out. If you blank mid-assessment, StealthCoder runs invisibly as a safety net, but the logic here is short enough to hold in your head.
The problem
A doubly linked list has one node per row of nodes. Row i is [value, specialIndex]: The node's left pointer targets row i - 1, or is null for the first row. The node's right pointer targets row i + 1, or is null for the final row. specialIndex is the row targeted by the node's arbitrary special pointer, or -1 for null. Build the list and create a deep copy. Every copied left, right, and special pointer must target only copied nodes. After copying, mutate the original node at mutationIndex: set its value to newValue and redirect its special pointer to newSpecialIndex, where -1 means null. Return two encoded snapshots in order: the mutated original list, then the unchanged deep copy. Function copyDoublyListWithSpecialPointer(nodes: int[][], mutationIndex: int, newValue: int, newSpecialIndex: int) → int[][][] Examples Example 1 nodes = [[7,2],[13,-1],[11,0]] mutationIndex = 1 newValue = 99 newSpecialIndex = 2 return = [[[7,2],[99,2],[11,0]],[[7,2],[13,-1],[11,0]]] The middle original node changes to [99,2]. The copied middle node remains [13,-1], proving that the copy is independent. Example 2 nodes = [[5,0]] mutationIndex = 0 newValue = 8 newSpecialIndex = -1 return = [[[8,-1]],[[5,0]]] The original loses its self-reference, while the copied node keeps its value and a special pointer to itself. Example 3 nodes = [[1,3],[2,0],[3,1],[4,2]] mutationIndex = 2 newValue = 30 newSpecialIndex = 3 return = [[[1,3],[2,0],[30,3],[4,2]],[[1,3],[2,0],[3,1],[4,2]]] The special pointers form a cycle. The mutation changes only the original third node; the cloned cycle stays unchanged. Constraints 1 <= nodes.length <= 50000. Every row contains exactly [value, specialIndex]. All node values and newValue fit a signed 32-bit integer. Every stored special index and newSpecialIndex is -1 or a valid row index. 0 <= mutationIndex < nodes.length. The returned deep-copy snapshot must retain every pre-mutation value and special link.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick: the input is already indexed, so you don't need a hash map or the interleaving trick. Build an array of original nodes, then build an array of copy nodes in a second pass. Wire left, right and special for both arrays using the same index math, so every copied pointer targets only copied nodes. Then apply the mutation to original[mutationIndex]: set value, and set special to original[newSpecialIndex] or null. Encode both lists by walking the arrays and emitting [value, specialIndex]. The pitfall is storing pointers and then trying to recover indices by searching, which turns O(n) into O(n^2) at 50000 nodes. Keep an index field on each node, or encode from the arrays directly. Also check self-reference (example 2) and cycles (example 3). StealthCoder is the hedge if the pointer wiring tangles live, but the array approach keeps it clean.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Copy a Doubly Linked List with a Special Pointer 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 for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
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 Microsoft's OA.
Microsoft reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Copy a Doubly Linked List with a Special Pointer FAQ
How hard is this Microsoft OA problem really?+
Medium at most. It's the classic copy-list-with-random-pointer idea, but the input is index-based, which removes the hardest part. The work is careful pointer wiring and encoding the output correctly. Most failures come from sloppy aliasing, not from algorithm difficulty.
What's the trick to the deep copy?+
Create all copy nodes first, stored in an array by row index. Then link left, right and special by index in a second pass. No hash map needed. Because every pointer is assigned from the copy array, nothing can accidentally reference an original node.
Why does the copy have to stay unchanged after mutation?+
The task checks independence. If any copied pointer targets an original node, the mutation shows up in the copy's snapshot. Example 1 shows this: the original middle node becomes [99,2] while the copy stays [13,-1].
What edge cases should I test?+
A single node whose special pointer targets itself (example 2), special pointers forming a cycle (example 3), special index -1, and a mutation that changes special to -1 or to another valid row. Also test the largest size, 50000 nodes, for linear time.
How do I prepare in 48 hours?+
Write the clone-with-random-pointer problem once from scratch, in both the hash map and index-array style. Practice encoding a list back to [value, index] rows. Then do a dry run on the three examples. That covers nearly everything this problem asks.