head and an integer pos. Find the pos-th node from the start and the pos-th node from the end (both counted from 1), and swap their values.
Return the head of the list.head=list_node([3, 6, 9, 12, 15, 18]), pos=2 → [3, 15, 9, 12, 6, 18]
The second node from the front holds 6 and the second from the back holds 15, so their values are exchanged.
head=list_node([5, 1, 7]), pos=2 → [5, 1, 7]
The second node from the front and from the back is the same node, so the list does not change.
head=list_node([40, 50]), pos=1 → [50, 40]
The first from the front is 40 and the first from the back is 50, so they swap.
n nodespos ≤ n ≤ 10⁵Node.val ≤ 100head=list_node([3, 6, 9, 12, 15, 18]), pos=2
[3, 15, 9, 12, 6, 18]
Run checks the first 3 tests in your browser. Submit checks all 93 tests on the server, hidden ones included.