Problem
You get head, the first node of a linked list, and a positive integer k. A linked list is a chain of nodes, and each node links to the next node.
Divide the list into groups of k nodes, from the start of the list. Reverse the order of the nodes in each full group. If fewer than k nodes remain at the end, keep them in their order.
Change only the links between the nodes, and do not change the values in the nodes. Return the head of the changed list.
Example 1
- Input:
- head = [2,4,6,8,10,12,14,16], k = 3
- Output:
- [6,4,2,12,10,8,14,16]
- Explanation:
- The full groups are
[2, 4, 6]and[8, 10, 12]. The last two nodes do not make a full group, so they keep their order.
Example 2
- Input:
- head = [9,8,7,6], k = 4
- Output:
- [6,7,8,9]
Example 3
- Input:
- head = [5,10,15], k = 1
- Output:
- [5,10,15]
- Explanation:
- Each group has one node, so the list does not change.
Constraints
- The number of nodes in the list is n.
- 1 <= k <= n <= 5000
- 0 <= Node.val <= 1000
Follow-up
Can you solve it with only O(1) extra memory?
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Reverse Linked List
Coding · Linked List · Recursion
- Add Two Numbers
Coding · Linked List · Math · Recursion
- Merge Two Sorted Lists
Coding · Linked List · Recursion
- Palindrome Linked List
Coding · Linked List · Recursion · Stack
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 2 records
Adobe
Leetcode 25. Reverse Nodes in k-Group
Reported Dec 31, 2025 · 1 source report
SENIOR
Source snapshot: Nov 12, 2026
View sourceMicrosoft
Leetcode 25. Reverse Nodes in k-Group
Reported May 31, 2026 · 1 source report
SENIOR
Source snapshot: Nov 12, 2026
View source
LeetCode company tags · 2 records
Microsoft
Reverse Nodes in k-Group
Reported date not specified · Source window: 30d
Source snapshot: Oct 20, 2026
Source frequency score: 61.5. This is not an interview probability.
View sourceTikTok
Reverse Nodes in k-Group
Reported date not specified · Source window: 6mo