#K52092. Remove the K-th Node from the End of a Linked List
Remove the K-th Node from the End of a Linked List
Remove the K-th Node from the End of a Linked List
You are given a singly linked list and an integer k. Your task is to remove the k-th node from the end of the list and output the modified list. If k is larger than the number of nodes in the list, the list should remain unchanged.
The algorithm involves using two pointers with a gap of k nodes between them to determine which node should be removed. Specifically, if the length of the list is n, you need to remove the node at position \(n - k + 1\) (using 1-indexing), provided that \(k \leq n\).
You are required to implement a solution that reads input from standard input (stdin) and writes the result to standard output (stdout).
inputFormat
The first line contains an integer n, the number of nodes in the linked list.
The second line contains n space-separated integers representing the node values.
The third line contains an integer k, indicating the position from the end of the list which should be removed.
outputFormat
Output the values of the linked list after the removal in a single line, with each value separated by a space. If the resulting list is empty, output nothing.## sample
5
1 2 3 4 5
2
1 2 3 5