Reverse nodes in k-groups

Write codeHard35 minMicrosoft style

Your task

Given a singly linked list encoded as a Python list of integers and an integer k, reverse the nodes of the list k at a time and return the resulting sequence as a Python list. Nodes in a final group with fewer than k elements are left as-is (not reversed). k is between 1 and the length of the list; the list has up to 5000 nodes.

Examples

reverse_k_group(values: list[int], k: int) -> list[int]
Example 1
Inputreverse_k_group([1, 2, 3, 4, 5], 2)
Output[2, 1, 4, 3, 5]