Geeksforgeeks

Error

×

Leaderboard

Showing:

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

@Ibrahim Nash | 5725 |

@blackshadows | 5685 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4908 |

@saiujwal13083 | 4156 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3511 |

@sushant_a | 3453 |

@KshamaGupta | 3318 |

@the_coder95 | 3302 |

Complete Leaderboard | |

Handle | Score |

@avaiesshaik782 | 662 |

@arpitsatnalika | 629 |

@code_it_ | 591 |

@prakharxyz | 583 |

@tujhekya | 542 |

@Rahul Jadhav 1 | 458 |

@sivanandh03 | 448 |

@satyam0460 | 433 |

@iamronak | 424 |

@imnm | 424 |

@18eumc107 | 421 |

Complete Leaderboard |

Given a doubly linked list, rotate the linked list counter-clockwise by P nodes. Here P is a given positive integer and is smaller than the count of nodes(N) in a linked list.

**Input:**

The first line of input contains an integer **T** denoting the no of test cases. For each test case, the first line of input contains two integers **N and P** denoting the number of nodes in Linked List and the number of nodes to be rotated respectively.

**Output:**

For each test case, output the final linked list after the P rotations in it**.**

**Constraints:**

1 <= T <= 100

2 <= N <= 100

1 <= P <= N

**Example:
Input:**

1

6 2

1 2 3 4 5 6

**Output:**

3 4 5 6 1 2

**Explanation:
Testcase 1:** Doubly linked list after rotating 2 nodes is: 3 4 5 6 1 2.

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
Rotate doubly Linked List

...

Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.