Your question is Reverse Linked List in K 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.
Autodesk Fusion 360 can represent design-history operations as a singly linked list. Given the list head and an integer k, reverse the nodes in consecutive groups of exactly k and return the new head.
The reversal must modify existing node links in place. If the final group contains fewer than k nodes, preserve that group’s original order.
Implement reverse_k_group(head, k), where head is either a ListNode or None, and each node has integer field val and pointer field next. Return the ListNode that begins the transformed list. Do not create replacement data nodes or convert the list to an array.
def reverse_k_group(head, k):