You are given the head of a singly linked list and a number k.
Your task is to swap the value of the node at position k from the start with the node at position k from the end of the list.
Remember the indexing starts from 1.
Input: head = [10, 20, 30, 40, 50], k = 1
Output: [50, 20, 30, 40, 10]
Explanation:
1st node from start is 10, 1st node from end is 50 → swap them.
Input: head = [2, 4, 6, 8], k = 3
Output: [2, 4, 8, 6]
Explanation:
3rd from start = 6, 3rd from end = 8 → swap.
Accepted:
Submission: