PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Meta

Deep copy a linked list with random pointers

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of linked-list structures, pointer/reference manipulation, deep versus shallow copying, and the ability to analyze time and space complexity.

  • medium
  • Meta
  • Coding & Algorithms
  • Machine Learning Engineer

Deep copy a linked list with random pointers

Company: Meta

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Problem You are given the head of a linked list where each node has: - `val`: integer value - `next`: pointer to the next node (or `null`) - `random`: pointer to any node in the list (or `null`) Return the head of a **deep-copied** linked list such that: - The copied list contains entirely new nodes (no node is shared with the original). - The `next` and `random` structure is preserved. ## Constraints - `0 <= n <= 10^5` - `-10^4 <= val <= 10^4` ## Requirements - Discuss time and space complexity. - Provide an approach that runs in **O(n)** time. - Explore an approach that uses **O(1)** extra space (not counting the output list itself), and explain tradeoffs vs. using a hash map. ## Example (conceptual) If node A’s `random` points to node C in the original list, then A’ (copy of A) must have `random` pointing to C’ (copy of C).

Quick Answer: This question evaluates understanding of linked-list structures, pointer/reference manipulation, deep versus shallow copying, and the ability to analyze time and space complexity.

Related Interview Questions

  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve a Key-Door Corridor Maze - Meta (medium)
  • Solve Array Merge and Parentheses Cleanup - Meta (medium)
  • Solve Two Backtracking Array Problems - Meta (hard)
  • Solve Maze and Suffix Problems - Meta (medium)
Meta logo
Meta
Jan 22, 2026, 12:00 AM
Machine Learning Engineer
Technical Screen
Coding & Algorithms
2
0
Loading...

Problem

You are given the head of a linked list where each node has:

  • val : integer value
  • next : pointer to the next node (or null )
  • random : pointer to any node in the list (or null )

Return the head of a deep-copied linked list such that:

  • The copied list contains entirely new nodes (no node is shared with the original).
  • The next and random structure is preserved.

Constraints

  • 0 <= n <= 10^5
  • -10^4 <= val <= 10^4

Requirements

  • Discuss time and space complexity.
  • Provide an approach that runs in O(n) time.
  • Explore an approach that uses O(1) extra space (not counting the output list itself), and explain tradeoffs vs. using a hash map.

Example (conceptual)

If node A’s random points to node C in the original list, then A’ (copy of A) must have random pointing to C’ (copy of C).

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Meta•More Machine Learning Engineer•Meta Machine Learning Engineer•Meta Coding & Algorithms•Machine Learning Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.