The PlayStation Store uses ordered navigation history entries for certain UI flows. Given the head of a singly linked list containing these entries, reverse the list in place and return the new head.
Your function receives a ListNode object. Each node has an integer val and a next reference, or None for the end of the list. Do not create replacement nodes or use an array to store the values. The test cases represent linked lists as arrays, and the test harness converts each array into a ListNode chain before calling the function. The returned list is serialized back to an array.
Implement reverse_linked_list(head), where head is a ListNode or None. Return the new head after reversing every next pointer. The original nodes must be reused.
def reverse_linked_list(head):