#K60312. Remove k-th Node from End of Linked List
Remove k-th Node from End of Linked List
Remove k-th Node from End of Linked List
In this problem, 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. If ( k ) is greater than the length of the list, the list should remain unchanged.
The linked list is represented by a sequence of integers, and the output should also be the modified list represented as a sequence of integers separated by spaces. If the resulting list is empty, output nothing.
inputFormat
The input is given via standard input in the following format:
(n) - the number of nodes in the linked list
(a_1\ a_2\ \dots\ a_n) - the elements of the linked list
(k) - the position (from the end) of the node to remove
For example:
5
1 2 3 4 5
2
outputFormat
Output the modified linked list as a sequence of integers separated by spaces. If the list becomes empty, output an empty line. For the sample input above, the output should be:
1 2 3 5## sample
5
1 2 3 4 5
2
1 2 3 5