Given the head of a linked list, reverse the nodes of the list `k` at a time and return the modified list. If the number of remaining nodes is less than `k`, leave them as-is. For example, given [1,2,3,4,5] and k = 2, reverse each pair: [2,1,4,3,5]. For k = 3, reverse the first group of 3 and leave the last 2: [3,2,1,4,5]. You may not alter the values in the nodes, only the nodes themselves may be changed.
Example 1
Input: head = [1,2,3,4,5], k = 2
Output: [2,1,4,3,5]
Explanation: Reverse each pair: [1,2] becomes [2,1] and [3,4] becomes [4,3]. The last node, 5, has no partner, so it stays as is.
Example 2
Input: head = [1,2,3,4,5], k = 3
Output: [3,2,1,4,5]
Explanation: The first three nodes [1,2,3] become [3,2,1]. Only two nodes remain after that, fewer than k = 3, so [4,5] stays as is.
Example 3
Input: head = [1,2,3,4,5], k = 1
Output: [1,2,3,4,5]
Explanation: With k = 1, every group is a single node, so the list does not change.
Walk the list in chunks of k. For each complete chunk, reverse the k nodes in place by rewiring their next pointers. Connect each reversed group to the next one.
Run checks all cases above. Submit evaluates all test cases.