Your question is Linked List or Bit Counting. 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.
Diagnostic pipelines in Texas Instruments Code Composer Studio may process records stored as singly linked lists. Given the head of a singly linked list and an integer k, reverse the list in consecutive groups of k nodes. If the final group contains fewer than k nodes, leave that group unchanged.
Implement reverse_in_groups(head, k), where head is either a ListNode object or None, and k is a positive integer. Each node has an integer val field and a next pointer. Return the head of the modified list. The reversal must be performed by changing pointers, not by creating replacement nodes or converting the entire list to an array.
For testing, linked lists are serialized as arrays. The evaluator converts each input array into linked nodes before calling the function and converts the returned list back into an array.
def reverse_in_groups(head, k):