Remove Nth Node From End of List
Remove the Nth node from the end of a linked list in a single pass.
Input format
The first line contains N and K (1 ≤ K ≤ N). The second line contains the N node values.
Output format
Remove the Kth node from the end and print the resulting list (print -1 if it becomes empty).
Constraints
- Values fit in a 64-bit signed integer
- Trailing whitespace and a trailing newline are ignored by the judge
Read from stdin, write to stdout. Sample cases below show the exact format.
Sample cases
Example 1
Input
5 2
1 2 3 4 5Expected output
1 2 3 5Example 2
Input
1 1
7Expected output
-1