Please enter your email address or userHandle.
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.
K = 4
Output: 4 2 2 1 8 7 6 5
K = 3
Output: 3 2 1 5 4
The task is to complete the function reverse() which should reverse the linked list in group of size k and return the head of the modified linked list.
Expected Time Complexity : O(n)
Expected Auxilliary Space : O(1)
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Login to access your submissions.
Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.