FastPrepCopy a Doubly Linked List with a Special Pointer
Problems/Copy a Doubly Linked List with a Special Pointer

Copy a Doubly Linked List with a Special Pointer

Microsoft logoMicrosoft● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Microsoft onsite interview. The report asks for a full copy of a doubly linked list where each node has an extra pointer to any node. It does not give a way to write the list so it can be run. Our version is about 95% the same as the reported question.

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, change 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 this order: the original list after the change, 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 = 1newValue = 99newSpecialIndex = 2return = [[[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 = 0newValue = 8newSpecialIndex = -1return = [[[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 = 2newValue = 30newSpecialIndex = 3return = [[[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.

More Microsoft Onsite Interview questions

  • Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Coin ChangeONSITE INTERVIEW · Seen Oct 2026
  • Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
  • Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Count Linked-List IslandsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Merge Event PreferencesAirbnb · PHONE SCREEN · ONSITE INTERVIEWAirbnb interview questions
  • Mutual-Friend Referral RecommendationsFireworks AI · PHONE SCREEN · ONSITE INTERVIEW
  • LRU CacheApple · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
  • LRU Cache for Query ResultsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • LRU CacheServiceNow · PHONE SCREEN · ONSITE INTERVIEWServiceNow interview questions
  • Package Install OrderVerily · ONSITE INTERVIEW
  • LRU CacheLotusFlare · ONSITE INTERVIEW
  • LRU CacheJP Morgan Chase · ONSITE INTERVIEWJP Morgan Chase interview questions

Microsoft interview experiences

  • Microsoft OA Questions, October 2026: 4 Experiences
  • Microsoft Experienced SWE Phone Screen: 1 Experience
  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int[][][] copyDoublyListWithSpecialPointer(int[][] nodes, int mutationIndex, int newValue, int newSpecialIndex) {
        // Write your code here.
    }
}
Checking account…