less than 1 minute read

You are given a singly linked list node and an integer k. Swap the value of the k-th (0-indexed) node from the end with the k-th node from the beginning.

Constraints

  • 1 ≤ n ≤ 100,000 where n is the number of nodes in node
  • 0 ≤ k < n

https://binarysearch.com/problems/Swap-Kth-Node-Values

Examples

Example 1

Input

  • node =
  • k = 1

Output

  • answer =

Explanation

We swap 2 and 5.

Example 2

Input

  • node =
  • k = 2

Output

  • answer =

Explanation

We swap 8 with 8.

Solution

Leave a comment