Dsa
Linked List
Medium
Reverse a Linked List in Groups of k
Given the head of a linked list, reverse the nodes of the list k at a time and return the modified list. If the number of nodes is not a multiple of k, then left-out nodes will remain as is.
Input Format: The first line contains an integer n, the number of nodes in the linked list. The second line contains k, the size of the groups. The next n lines contain integers, the values of the nodes.
Output Format: Print the values of the modified linked list.
Example:
Input:
5
3
1
2
3
4
5
Output:
3 2 1 4 5
Key concepts
linked_listreversalgrouping
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now