Your question is Reverse 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.
San Diego Staffing stores a sequence of candidate records in a singly linked list. Reverse the list in place and return the new head so the records appear in the opposite order.
Implement reverse_linked_list(head), where head is either a ListNode representing the first node or None. Each node has a val field and a next field. Return the new head after reversing every next pointer. Do not create new list nodes.
For examples and test cases, linked lists are represented as arrays of node values. The evaluator converts the input array into a linked list before calling the function and converts the returned list back into an array.
def reverse_linked_list(head):