Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6420 |

@blackshadows | 6376 |

@mb1973 | 5578 |

@Quandray | 5231 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4510 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3412 |

Complete Leaderboard | |

Handle | Score |

@codersgroup18 | 714 |

@Manikanta punnam | 579 |

@sriramgoparaju99 | 532 |

@yashkaril4 | 517 |

@praveenbgp6 | 517 |

@prankursharma31 | 489 |

@rdakka | 465 |

@sonamnigam1999 | 441 |

@purohitmn02 | 427 |

@sonamkumari63928 | 426 |

@ShubhankarPandey | 419 |

Complete Leaderboard |

You are given a special linked list with **N **nodes where each node has a next pointer pointing to its next node. You are also given **M** random pointers , where you will be given **M **number of pairs denoting two nodes **a** and **b** **i.e. **a->arb = b**.**

**Example 1:**

**Input:
**N = 4, M = 2
value = {1,2,3,4}
pairs = {{1,2},{2,4}}
**Output: **1**
Explanation: **In this test case, there
re 4 nodes in linked list. Among these
4 nodes, 2 nodes have arbit pointer
set, rest two nodes have arbit pointer
as NULL. Second line tells us the value
of four nodes. The third line gives the
information about arbitrary pointers.
The first node arbit pointer is set to
node 2. The second node arbit pointer
is set to node 4.

**Example 2:**

**Input:
**N = 4, M = 2
value[] = {1,3,5,9}
pairs[] = {{1,1},{3,4}}
**Output: **1**
Explanation: **In the given testcase ,
applying the method as stated in the
above example, the output will be 1.

**Your Task:**

The task is to complete the function **copyList**() which takes one argument the head of the linked list to be cloned and should **return** the head of the cloned linked list.

**NOTE : **If their is any node whose arbitrary pointer is not given then its by default null.

**Expected Time Complexity** : O(n)

**Expected Auxilliary Space **: O(1)

**Constraints:**

1 <= N <= 100

1 <= M <= N

1 <= a, b <= 100

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Clone a linked list with next and random pointer

...