Given the head of a linked list, reverse the nodes of the list in groups of size k and return the new head.
• k is a positive integer and k ≤ the length of the list.
• If the number of nodes at the end is less than k, leave them as they are.
• Only the node links may be changed, not the node values.
Input: head = [10,20,30,40,50,60], k = 3
Output: [30,20,10,60,50,40]
Explanation:
The first three nodes are reversed, then the next three.
Input: head = [5,6,7,8,9], k = 2
Output: [6,5,8,7,9]
Explanation:
Nodes are reversed in pairs; the last node remains as is.
Input: head = [1], k = 1
Output: [1]
Explanation:
A single node stays the same.
Accepted:
Submission: