Delete Nth Node From End of List - aloalgo

Delete Nth Node From End of List

Medium

You are given the head of a singly linked list, remove the nth node from the end of the list and return its head.

Follow-up

Could you do this in one pass?

Example 1

Inputs
head = 1 → 2 → 3 → 4 → 5 → null
n = 2
Output
1 → 2 → 3 → 5 → null
Explanation:

The 2nd node from the end is 4. Removing it results in the list 1->2->3->5.

Example 2

Inputs
head = None
n = 1
Output
None
Explanation:

The list has only one node. Removing the 1st node from the end leaves an empty list.

Example 3

Inputs
head = 1 → 2 → null
n = 1
Output
1 → null
Explanation:

The 1st node from the end is 2. Removing it leaves the list 1.

Loading...
Inputs
head = 1 → 2 → 3 → 4 → 5 → null
n = 2
Output
1 → 2 → 3 → 5 → null

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!