Your question is Reversing a 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.
Judge Group's internal engineering tools use singly linked lists for ordered processing tasks. Implement a function that reverses a singly linked list in place and returns the new head.
Each node has an integer value and a next pointer. The function receives head, a ListNode reference or None, and returns the new ListNode head after reversing every link. Do not create replacement nodes or use an array to store the values. The original nodes must be reused.
For examples and test cases, linked lists are represented as arrays from head to tail. The evaluator converts an input array into linked nodes before calling the function and serializes the returned list back into an array.
def reverse_linked_list(head):