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.
Flexport may store shipment events in chronological order as a singly linked list. Given the head of this list, reverse the list in place so the most recent event becomes the first node.
Implement reverse_linked_list(head) and return the new head. Each node has a value field and a next pointer. The evaluator constructs the linked list before calling your function and serializes the returned list back to an array of values for verification.
Your solution must relink existing nodes rather than create replacement nodes. Handle empty lists and lists containing a single node.
head, either None or a reference to the first ListNode in a singly linked list.next pointer.ListNode contains value and next.def reverse_linked_list(head):