Remove Nth Node From End
Problem Statement
Given the head of a singly linked list and an integer
, remove the node at the
-th position from the end of the list.
Rules and Constraints
- The linked list is 1-indexed.
- The size of the list is , and is guaranteed to be within the valid range .
- The list does not contain duplicates and nodes do not have a value that is the same as .
- It is not allowed to access the list in a reverse direction.
- The time complexity of the solution should be O(L), where is the length of the list.
- The space complexity of the solution should be O(1).
Note that the problem is asking to remove the node at the
-th position from the
end of the list, not from the beginning.
Example
Input: {"head":[1,2,3,4,5],"n":2}
Output: [1,2,3,5]