Your question is Reverse a Linked List In-Place. 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 HashedIn QA automation pipeline stores execution steps as a singly linked list. Given the head of the list, reverse the list in-place and return the new head.
You must modify the existing next pointers rather than creating replacement nodes or copying values. The solution must be iterative so it remains safe for very long lists.
Define a node as having an integer value and a nullable next reference. Implement reverse_list(head), where head is either a ListNode or None. Return the head of the reversed list. The original nodes must be reused, and the final node in the reversed list must point to None.
The test cases represent linked lists as arrays of values. The evaluator converts each array into linked nodes before calling the function and converts the returned list back into an array.
def reverse_list(head):