Your question is QA Coding: Reverse Linked List. 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.
A Thomson Reuters Westlaw processing component stores ordered result references in a singly linked list. Implement a function that reverses the list in place and returns the new head.
The nodes must be reused. Do not create replacement nodes or copy values into another collection. Your solution should clearly preserve the unreversed portion of the list while changing each node's next pointer exactly once.
Input is head, either None or a reference to the first ListNode. Each node has a value field and a next field, where next is another ListNode or None. The input list is finite and acyclic. Return the new head after reversal. The grader serializes linked lists as JSON arrays for test cases and converts them to ListNode objects before calling the function.
def reverse_linked_list(head):