Reverse a Linked List in groups of given size.
Medium Accuracy: 45.83% Submissions: 70133 Points: 4

Given a linked list of size N. The task is to reverse every k nodes (where k is an input to the function) in the linked list.

Example 1:

LinkedList: 1->2->2->4->5->6->7->8
K = 4
Output: 4 2 2 1 8 7 6 5

Example 2:

LinkedList: 1->2->3->4->5
K = 3
Output: 3 2 1 5 4

Your Task:
The task is to complete the function reverse() which should reverse the linked list in group of size and return the head of the modified linked list.

Expected Time Complexity : O(N)
Expected Auxilliary Space : O(1)

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?


All Submissions

My Submissions:

Login to access your submissions.

Reverse a Linked List in groups of given size.

Output Window