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 nodes is not a multiple of k, the leftover nodes at the end should remain as they are. You may not alter node values, only the nodes themselves.
Input: values = [1,2,3,4,5], k = 2
Output: [2,1,4,3,5]
Topics: linked-list
Asked by: Amazon, Microsoft, Meta, Google
Time complexity: O(n). Space complexity: O(1) extra space.