Dsa
Linked List
Hard
Reverse a Linked List in Groups of K
Given a linked list and an integer k, reverse the nodes of the linked list k at a time and return its modified list. If the number of nodes is not a multiple of k, then left-out nodes in the end should remain as they are.
Input Format:
The first line contains a space-separated list of integers representing the linked list elements. The second line contains a single integer k.
Output Format:
Print the modified linked list as a space-separated string of integers.
Example:
Input:
1 2 3 4 5
2
Output:
2 1 4 3 5
Key concepts
linked_listgroup_reversalrecursion
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