Dsa
Linked List
Easy
Reverse K-Group
Given the head of a linked list and an integer k, 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 in the end should remain as-is. You may not alter the values in the nodes, only the nodes themselves should be reversed.
### Input Format:
- The first line contains an integer n, the number of nodes in the linked list.
- The following n lines each contain a single integer, denoting the value of each node.
- The last line contains the integer k.
### Output Format:
- Print the values of nodes in the modified linked list in order, separated by spaces.
### Example:
Input:
5
1
2
3
4
5
3
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