Tap here to switch tabs
Problem
Submissions

Problem: Swapping Nodes in a Linked List

Swapping Nodes in a Linked List asks you to exchange the values of the kth node from the start and the kth node from the end, then return the resulting list's head.

Statement

Given the head of a linked list and an integer, k, return the head of the linked list after swapping the values of the kthk^{th} node from the beginning and the kthk^{th} node from the end of the linked list.

Note: We’ll number the nodes of the linked list starting from 11 to nn.

Constraints:

  • The linked list will have n number of nodes.
  • 1≤1 \leq k ≤\leq n ≤500\leq 500
  • −5000≤-5000 \leq Node.value ≤5000\leq 5000
⋮
Tap here to switch tabs
Problem
Submissions

Problem: Swapping Nodes in a Linked List

Swapping Nodes in a Linked List asks you to exchange the values of the kth node from the start and the kth node from the end, then return the resulting list's head.

Statement

Given the head of a linked list and an integer, k, return the head of the linked list after swapping the values of the kthk^{th} node from the beginning and the kthk^{th} node from the end of the linked list.

Note: We’ll number the nodes of the linked list starting from 11 to nn.

Constraints:

  • The linked list will have n number of nodes.
  • 1≤1 \leq k ≤\leq n ≤500\leq 500
  • −5000≤-5000 \leq Node.value ≤5000\leq 5000