Your question is Reverse Linked List Between Positions. 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.
Freshdesk can represent an ordered chain of ticket-processing steps as a singly linked list. Given the chain's head and two 1-indexed positions, reverse the nodes from left through right while preserving every node outside that range.
Implement reverse_between(head, left, right) and return the new head. The reversal must be performed by changing pointers, not by creating replacement nodes or copying values.
head is either the first ListNode in a singly linked list or None.ListNode has an integer val field and a next field.left and right are valid 1-indexed positions, with left <= right.def reverse_between(head, left, right):