Your question is Reverse Linked List in Groups. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
AutoRABIT Holding processes ordered deployment records represented as a singly linked list. Given the list head and an integer k, reverse the nodes in every consecutive group of k nodes and return the new head.
If fewer than k nodes remain at the end, leave that final group unchanged. Nodes must be rearranged in place, without creating replacement nodes or copying values.
Implement reverse_k_group(head, k), where head is either None or the head of a singly linked ListNode with fields val and next, and k is a positive integer. Return the head of the transformed linked list. Test inputs serialize linked lists as arrays, and the evaluator converts them to ListNode objects before calling the function. Outputs are serialized back to arrays.
def reverse_k_group(head, k):