...

/

Swap Nth Node with Head

Swap Nth Node with Head

Given the head of a singly linked list and 'n', swap the head with the nth node. Return the head of the new linked list.

Statement

Given the head of a singly linked list and nn, swap the head with the nthn^{th} node. Return the head of the new linked list.

Example

Let’s take a look at an example where n is equal to 44.

g head head 7 7 head->7 NULL NULL 28 28 35 35 28->35 14 14 7->14 21 21 14->21 21->28 42 42 35->42 42->NULL

After swapping the Nth node with head, ...

Access this course and 1400+ top-rated courses and projects.