You are given the head of a singly linked list, remove the nth node from the end of the list and return its head.
Could you do this in one pass?
head = 1 → 2 → 3 → 4 → 5 → null
n = 2
1 → 2 → 3 → 5 → null
The 2nd node from the end is 4. Removing it results in the list 1->2->3->5.
head = None
n = 1
None
The list has only one node. Removing the 1st node from the end leaves an empty list.
head = 1 → 2 → null
n = 1
1 → null
The 1st node from the end is 2. Removing it leaves the list 1.
head = 1 → 2 → 3 → 4 → 5 → null
n = 2
1 → 2 → 3 → 5 → null