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.

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.