Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

nodes =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

Interleave copied nodes with original nodes to avoid a hash map.

Approach

  1. For each original node, insert its copy right after it.
  2. Set copy random pointers using original.random.next.
  3. Detach the copied list from the interleaved structure.

Why it works

Each copy sits next to its original, so you can resolve random pointers in O(1) without extra mapping.

Code
Loading...
Complexity
Time: O(n)
Space: O(1)
Solution
Updated: 2026-02-23

Idea

Interleave copied nodes with original nodes to avoid a hash map.

Approach

  1. For each original node, insert its copy right after it.
  2. Set copy random pointers using original.random.next.
  3. Detach the copied list from the interleaved structure.

Why it works

Each copy sits next to its original, so you can resolve random pointers in O(1) without extra mapping.

Code
Loading...
Complexity
Time: O(n)
Space: O(1)