advanced8 min read·Updated September 23, 2026

Copy List with Random Pointer Explained: 7→13→11→10→1 Clone Trace

Master the Copy List with Random Pointer problem with a step-by-step trace of 7→13→11→10→1. Learn the interleaving mental model for $O(1)$ space cloning.

By Learnisim AI·Published September 23, 2026
LEARNING ARCSetup → Model in the example → Full trace → Twist → Edge cases → Apply
PREREQUISITES
  • Singly linked list basics
  • Pointer manipulation
  • Basic hash map concepts
Why

Why copying a linked list with random pointers breaks standard cloning

Phase 1: The Broken Clone Trap

Imagine you are handed a linked list where every node has two pointers: a standard next pointer and a random pointer that can reference any node in the list or be null. Specifically, consider our working example: nodes are arranged in the exact order 7 13 11 10 1, with random pointers mapping 7 null, 13 7, 11 1, 10 11, and 1 7.
If you try to copy this structure using a naive two-pass approach—building the next chain first, then attempting to assign the random pointers—you immediately hit a wall. When you look at the clone of node 13, you know its original random points to node 7. But in your newly allocated list, which node corresponds to 7? Without keeping track of object memory addresses or modifying the structure, you cannot simply look up an arbitrary node in time.
Trying
Why Copying a Linked List with Random Pointers Breaks Standard Cloning Example List: 7 -> 13 -> 11 -> 10 -> 1 (with complex random pointer mapping) Original List (Access to Memory Addresses) Val: 7 next rand Val: 13 next rand Val: 11 next rand Val: 10 next rand Val: 1 next rand 7 → null Clone List (Naive Pass 1: Standard Copy without Mapping) Copy 7 next rand Copy 13 next rand Copy 11 next rand Copy 10 next rand Copy 1 next rand Which node is '7'? O(N) Solution: Use a Hash Map {OriginalNode → CloneNode} OR Interweave nodes (A → A' → B → B') to map randoms in O(1)
Why copying a linked list with random pointers breaks standard cloning diagram
Model

Building the Interleaved Interweaving Mental Model

Phase 2: The Interleaved Node Model

When we look at our locked working example of copying the list , a standard deep copy fails because a node's pointer might reference a node we haven't visited yet, or it might point backward in a way our single pass cannot resolve. To solve this without a secondary hash map, we use an interleaved node model that relies entirely on physical structural placement.
Imagine taking our original list and inserting each newly created clone directly adjacent to its original counterpart. For instance, node is immediately followed by its clone , which is then followed by original node , then its clone , and so on. In this interwoven topology, the relationship between an original node and its clone becomes deterministic: if an original node is at pointer , its clone is always at .
This physical proximity solves the pointer mystery. If original node has a pointer targeting original node , where does clone 's pointer need to point? It must point to clone . Since clone sits immediately after original node (meaning at ), we can find the exact target for our clone's pointer by inspecting .
The Interleaved Interweaving Model (O(1) Space Copy List with Random Pointer) Formula for Random: clone.random = curr.random ? curr.random.next : null Phase 1: Original List (7 -> 13 -> 11) Val: 7 rand: null Val: 13 rand: 7 Val: 11 rand: 1 ... Phase 2: Interleaved Insertion (curr.next = clone, clone.next = next) 7 Orig 7' Clone 13 Orig 13' Clone 11 Orig 11' Clone 13'.random = 13.random.next (7') The 3-Step Magic 1 Interleave clones: A -> A' -> B -> B' 2 Assign randoms: clone.random = curr.random.next 3 Restore lists: Unweave original & clone list apart Why it works O(1) Space: No Hash Map needed! Topology provides pointer mapping natively. The Deterministic Physical Proximity Insight: • Because clone 13' sits immediately after original 13 (at curr.next), • And target clone 7' sits immediately after original target 7, • We resolve random pointers in constant time without extra memory structures. Result: Clean separation, O(N) time, and O(1) auxiliary space achieved.
Building the Interleaved Interweaving Mental Model diagram
Worked example

Tracing the Interleaving Copy Algorithm Step-by-Step

Phase 3: Worked Example

To see how the interweaving mental model operates in practice, let us trace our locked example: cloning the list where the random pointers are given by , , , , and .
Given:
- Original nodes in sequence:
- Original next pointers:
- Original random pointers: , , , ,
Steps:
1.Pass 1: Interleave clone nodes. We insert a duplicate clone immediately after every original node.

- State after Pass 1:
2. Pass 2: Assign random pointers. For each original node , its clone is . Therefore, must point to the clone corresponding to . Using our identity formula, (if is not null).
- For : is , so .
- For : is 7, so .
- For : is 1, so .
- For : is 11, so .
- For : is 7, so .
3.Pass 3: Unweave the lists. We separate the interleaved chain back into two independent lists by restoring original next pointers and assigning clone next pointers.

- Original list:
- Cloned list:
Result:
A fully independent cloned list whose random pointers match the expected shape (, , , , ), completely isolated from the original memory locations.
Try this: Given the intermediate state after Pass 1: 7 -> 7' -> 13 -> 13' -> 11 -> 11' -> 10 -> 10' -> 1 -> 1' -> null, and the original random pointer 10 -> 11, write out the exact pointer assignment expression used in Pass 2 to set 10'.random.
Phase 3 Worked Example: Interleaving Trace & Pass 2 Randoms Focus: $10 \to 11$ original random maps to clone formula $10'.\text{random} = 11.\text{next} = 11'$ Pass 1 State (Interleaved Chain): 7 7' 13 13' 11 11' 10 10' 1 1' Original nodes (blue) Cloned nodes inserted immediately after (teal) Pass 2: The Random Pointer Formula Identity: N'.random = N.random.next 1. Take original node N (10) 2. Find N.random (points to 11) 3. Result: 10'.random = 11.next = 11' Clone 10' successfully links to clone 11'! Pointer Assignment Arc ($10' \to 11'$) 10 10' 10.random = 11 11 11' .next 10'.random = 11' Bypasses O(N) hash search!
Tracing the Interleaving Copy Algorithm Step-by-Step diagram
Practice

Predicting the Intermediate State During Pass 2

Phase 4: Practice

Now that you have seen how the three-pass interweaving algorithm handles the locked sequence of nodes , it is time to check your mental model of the wiring phase. Recall that Pass 2 is responsible for establishing the random pointers of every cloned node by looking directly at the adjacent original node's random pointer.
Consider the cloned node for 13, let us call it . According to our locked working example, the original node 13 has a random pointer directed at 7. When Pass 2 executes, how do we correctly assign using the interleaved structure where every original node is immediately followed by its clone?
Work through the pointer adjustment for using the interleaved state formed after Pass 1, keeping in mind how original.random.next reaches the corresponding clone.
Apply

Applying the Interleaving Pointer Pattern to New Graph Topologies

Phase 5: Apply

Now that you have successfully cloned our locked sequence using the three-pass interweaving pattern, let us see how this exact same mental model transfers to a more extreme pointer topology. Imagine you are given a graph where every single node's random pointer creates a strict cycle, such that node , or a scenario where all random pointers are null.
By keeping the foundational three-pass procedure intact—interleave clones, wire random pointers via orig.random.next, and unweave—you eliminate the need for any auxiliary hash map storage, keeping space complexity at . When faced with a new pointer-doubling problem in interviews or systems programming, look for whether you can temporarily augment the existing memory layout rather than allocating a separate index dictionary.

Phase 5: Practical Vignette

Suppose you encounter a variant of our locked list where every node's random pointer points directly to itself instead of pointing to other nodes in the sequence . Walk through Pass 2 under this self-referential topology: what does clone.random evaluate to when orig.random is orig itself?
python
def apply_self_loops(head):
    # Pass 1: Interleave
    curr = head
    while curr:
        new_node = Node(curr.val, curr.next, None)
        curr.next = new_node
        curr = new_node.next
    
    # Pass 2: Wire randoms where every node points to itself
    curr = head
    while curr:
        if curr.random:
            curr.next.random = curr.random.next
        curr = curr.next.next

FAQ

How do random pointers break standard linked list cloning?
Standard cloning only copies the 'next' pointer iteratively. When a node has a 'random' pointer pointing ahead or behind, the target node of that random pointer might not have been created yet in the new list, leading to broken references or requiring an hash map.
How does the interleaved interweaving mental model handle random pointers in the 7→13→11→10→1 example?
In Pass 1, we create clone nodes and weave them directly after their originals (e.g., 7 → 7' → 13 → 13'). Because every clone sits immediately next to its original, finding the clone of any random target is trivial: original.random.next gives the corresponding clone.
What is the time and space complexity of the interleaved cloning approach?
The time complexity is because we traverse the list three times (interweaving, assigning random pointers, and separating the lists). The space complexity is auxiliary space since we reuse the existing list structure instead of using a hash map.
What happens during Pass 2 of the interleaving copy algorithm?
During Pass 2, we iterate through the interleaved list to wire up the random pointers. For each original node, its clone's random pointer is set using 'original.random.next', safely linking to the newly created clone node.

Keep learning