Your question is Reverse Linked List Subrange. 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.
Etsy may represent a sequence of listing identifiers as a singly linked list while preparing a reordered view. Given the list head and two 1-indexed positions, reverse the nodes between those positions in place and return the new head.
Implement reverse_between(head, left, right), where head is the head of a singly linked list whose nodes have a val field and a next field. left and right are 1-indexed positions, inclusive. Reverse the links for that contiguous segment without creating replacement nodes, and return the resulting list head. The input list must be modified in place.
The test harness represents a linked list as a Python array and converts it to linked nodes before calling your function. It converts the returned list back to an array for comparison.
def reverse_between(head, left, right):