Hard

Quiz

#25 Reverse Nodes in k-Group

APPROACH

Reverse the nodes of linked list head in consecutive groups of k and return the new head. Any trailing nodes that do not fill a complete group of k remain in their original order. Node values may not be changed.

Example 1:

Input: head = [1,2,3,4,5], k = 2
Output: [2,1,4,3,5]

Example 2:

Input: head = [1,2,3,4,5], k = 3
Output: [3,2,1,4,5]
1 of 4
1:00

What is the optimal approach for this problem?