Given a linked list, reverse the nodes k at a time and return the modified list, using only O(1) extra space. Nodes in a final group of fewer than k are left in their original order. The list is given as an array; return the result as an array. Input: '[list], k'.
Input: '[list], k'.
Output: Array — the modified list.
Input: [1,2,3,4,5], 2
Output: [2,1,4,3,5]
Explanation: Full pairs reversed; last node unchanged.Input: [1,2,3,4,5], 3
Output: [3,2,1,4,5]
Explanation: First triple reversed.Input: [1], 1
Output: [1]
Explanation: Single node.0<=n<=50001<=k<=n