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.
First line of input contains number of testcases T. For each testcase, first line contains length of linked list and next line contains the linked list elements.
For each testcase, there will be a single line of output which contains the linked list with every k group elements reversed.
The task is to complete the function reverse() which should reverse the linked list in group of size k.
1 2 2 4 5 6 7 8
4 2 2 1 8 7 6 5
Testcase 2: Since, k = 4. So, we have to reverse everty group of two elements. Modified linked list is as 4, 2, 2, 1, 8, 7, 6, 5.
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.