Solution: Swapping Nodes in a Linked List
Let's solve the Swapping Nodes in a Linked List problem using the In-Place Manipulation of a Linked List pattern.
We'll cover the following...
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 node from the beginning and the node from the end of the linked list.
Note: We’ll number the nodes of the linked list starting from to .
Constraints:
- The linked list will have
n
number of nodes. -
k
n
-
Node.value
Pattern: In-place Manipulation of a Linked List
We need to find the node from the start of the linked list and the ...