Remove Nth Node From End of List
Remove the nth node counted from the end of an acyclic list and return the resulting head.
Example 1
head = [5,6,7,8]
n = 2[5,6,8]Explanation
Counting backwards gives 8 first and 7 second; remove 7 and join 6 to 8.
Example 2
head = [9]
n = 1nullExplanation
Removing the only node leaves an empty list.
Example 3
head = [1,2]
n = 2[2]Explanation
The second node from the end is head 1, so head becomes 2.
Constraints
- 1 <= n <= number of nodes <= 10000
Function contract
removeNthFromEndArguments: list, jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.
[5,6,7,8]2