Submissions : 5573 Accuracy :


Rotate a Linked List (Function Program)

Given a singly linked list, rotate the linked list counter-clockwise by k nodes. Where k is a given positive integer smaller than or equal to lenght of the linked list. For example, if the given linked list is 10->20->30->40->50->60 and k is 4, the list should be modified to 50->60->10->20->30->40.

Note: Function may assume that k is smaller than the count of nodes in linked list.


In this problem, complete the method which takes two argument: the head of the linked list and int k. We should not read any input from stdin/console.
The struct Node has a data part which stores the data and a next pointer which points to the next element of the linked list. 
There are multiple test cases. For each test case, this method will be called individually.

Rotate the link list from index k and return its new head pointer.

Note: If you use "Test" or "Expected Output Button" use below example format

1 2 3 4 5 6 7 8

5 6 7 8 1 2 3 4

**For More Examples Use Expected Output**

Contributor: Harshit Sidhwa,Saksham Raj Seth

It is recommended to test your code before clicking 'Submit' button!


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