head and two positions start ≤ end (nodes are numbered from 1). Reverse the part of the list from node start to node end inclusive and leave every other node where it is. Return the head of the resulting list.
Try to do it in a single pass.head=list_node([7, 3, 8, 1, 6, 2]), start=2, end=5 → [7, 6, 1, 8, 3, 2]
Nodes 2 through 5 are 3, 8, 1, 6; reversing them gives 7, 6, 1, 8, 3, 2.
head=list_node([-4, 9]), start=1, end=2 → [9, -4]
The whole list gets reversed.
head=list_node([11, 12, 13]), start=3, end=3 → [11, 12, 13]
A segment of one node leaves the list unchanged.
head=list_node([7, 3, 8, 1, 6, 2]), start=2, end=5
[7, 6, 1, 8, 3, 2]
Run checks the first 3 tests in your browser. Submit checks all 99 tests on the server, hidden ones included.