Timer is Running

Rotate doubly Linked List
Submissions: 8807   Accuracy:


  Difficulty: Easy   Marks: 2
Associated Course(s):   Interview Preparation

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.

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.

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

1 <= T <= 100
2 <= N <= 100
1 <= P <= N


6 2
1 2 3 4 5 6

3 4 5 6 1 2

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


** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Saksham_A
Author: saksham0751

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.