Swap Nth Node with Head
Understand how to swap the head node with the nth node in a singly linked list. This lesson teaches you to traverse the list, identify nodes, and perform the swap with linear time and constant space complexity.
We'll cover the following...
We'll cover the following...
Statement
Given the head of a singly linked list and , swap the head with the node. Return the head of the new linked list.
Example
Let’s take a look at an example where n is equal to .
After swapping the Nth node with head, our ...