#K69807. Remove N-th Node from End of Linked List

    ID: 33168 Type: Default 1000ms 256MiB

Remove N-th Node from End of Linked List

Remove N-th Node from End of Linked List

You are given a singly linked list and an integer n. Your task is to remove the n-th node from the end of the list and then output the modified list.

For example, if the linked list is 1 2 3 4 5 and n = 2, then after removing the 2nd node from the end, the list becomes 1 2 3 5.

Note: Try to design a solution that makes a single pass over the list. In mathematical notation, if the linked list has T nodes, with nodes represented as \( a_1, a_2, \dots, a_T \), then you are required to remove the node \( a_{T-n+1} \). Be sure to handle edge cases such as when the list becomes empty after removal.

inputFormat

The input is read from stdin and has the following format:

  1. An integer T representing the number of nodes in the linked list.
  2. T space-separated integers representing the values of the nodes.
  3. An integer n indicating the n-th node from the end to remove.

outputFormat

Output the values of the linked list after removing the requested node. The values should be printed on a single line, separated by spaces. If the list is empty, output nothing.

## sample
5
1 2 3 4 5
2
1 2 3 5