FastPrepMeta Copy List with Random Pointer
Problems/Meta Copy List with Random Pointer

Meta Copy List with Random Pointer

Meta logoMeta● MediumFULLTIMEPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Meta onsite interview. The report names the well-known task of deep-copying a list with random pointers but does not give the interface. We encode the list, and we change the copy afterward to show that the two lists are independent. Our version is about 85% the same as the reported question.

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. Preserve the original next-pointer chain after copying. 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.

For an empty list, use mutationIndex = -1 and newRandomIndex = -1; return two empty snapshots.

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 = 1newValue = 130newRandomIndex = 4return = [[[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 = 0newValue = 10newRandomIndex = -1return = [[[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 = 0newValue = 6newRandomIndex = -1return = [[[6,-1]],[[5,0]]]

The one-node copy keeps its self-random pointer even after the original is changed.

Example 4

nodes = []mutationIndex = -1newValue = 0newRandomIndex = -1return = [[],[]]

An empty list has no node to copy or mutate, so both snapshots are empty.

Constraints

  • 0 <= nodes.length <= 10^4.
  • Every row of nodes contains exactly two integers.
  • -10^9 <= nodes[i][0], newValue <= 10^9.
  • For a nonempty list, every random index and newRandomIndex is -1 or an index from 0 through nodes.length - 1. For an empty list, newRandomIndex = -1.
  • For a nonempty list, 0 <= mutationIndex < nodes.length. For an empty list, mutationIndex = -1.

More Meta Onsite Interview questions

  • Multi-Head Attention Forward PassPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Run-Length Encoded Vector Dot ProductPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Mutual-Friend RecommendationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Deterministic K-Means AssignmentsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Linear Layer Forward and Backward PassesONSITE INTERVIEW · Seen Sep 2026
  • Reservoir Sampling with Recorded DrawsONSITE INTERVIEW · Seen Sep 2026
  • Stochastic Gradient Descent with MomentumONSITE INTERVIEW · Seen Sep 2026
  • Top K Largest Values with a HeapONSITE INTERVIEW · Seen Sep 2026
  • Partition a Card Deck into FifteensONSITE INTERVIEW · Seen Sep 2026
  • Insert into a Sorted Circular ListONSITE INTERVIEW · Seen Aug 2026

Similar questions at other companies

  • Deep Copy a Random-Pointer ListAmazon · ONSITE INTERVIEW
  • Deep Copy a Random-Pointer ListBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Deep Copy a Random-Pointer ListSuperhuman · PHONE SCREENSuperhuman interview questions
  • Sustained Overspeed AlertsFleetx · ONSITE INTERVIEW
  • LRU CacheAthenahealth · PHONE SCREEN
  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • Random Dasher Set OperationsDoorDash · ONSITE INTERVIEWDoorDash interview questions
  • LRU CacheApple · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
  • LRU CacheServiceNow · PHONE SCREEN · ONSITE INTERVIEWServiceNow interview questions
  • Logger Rate Limiter with Every-Arrival HistoryGoogle · PHONE SCREENGoogle interview questions

Meta interview experiences

  • Meta PhD SWE Intern AI Coding Phone Screen: 1 Experience
  • Meta Business Support Engineer Phone Screen: 1 Experience
  • Meta Software Engineer Onsite Questions: 3 Experiences
  • Meta AI Native Engineer OA and Onsite: 1 Experience
  • Meta AI-Native Coding Interview: 3 Experiences
  • Meta Production Engineer Intern Questions: 6 Experiences
All Meta interview questionsSee Meta hiring insights
Saved
class Solution {
    public int[][][] copyAndMutateRandomList(int[][] nodes, int mutationIndex, int newValue, int newRandomIndex) {
      // write your code here
    }
}
Checking account…