Copy List

A linked list is given such that each node contains an additional random pointer which could point to any node in the list or NULL.

Return a deep copy of the list.


Given list

   1 -> 2 -> 3

with random pointers going from

  1 -> 3
  2 -> 1
  3 -> 1

You should return a deep copy of the list. The returned answer should not contain the same node as the original list, but a copy of them. The pointers in the returned list should not link to any node in the original input list.

Interview Code Editor
  • Solution Approach
  • Complete Solution
3399 successful submissions.
Asked In:
  • Amazon
  • Microsoft
Click here to jump start your coding interview preparation