Dsa
Linked List
Easy
Reverse Linked List in Groups
Given a singly 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, leave the last nodes as is. You must do this in-place and use only constant extra space.
Input format:
- The first line contains an integer n, the number of nodes in the list.
- The second line contains n integers, the node values of the list.
- The third line contains an integer k, the group size for reversal.
Output format:
- Print the transformed list as space-separated integers in order.
Example:
Input:
5
1 2 3 4 5
2
Output:
2 1 4 3 5
Key concepts
linked_listgroupingreversal
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