Delete Xth Node From End of Linked List

Medium

Given a linked list, delete the xth node from the end.

Example:

Linked list: 1→2→3→4

x: 2

Result: 1→2→4

Testing

Input Format

The first line contains an integer ‘T’ denoting the number of independent test cases.

For each test case the input has three lines:

  • An integer ‘n’ denoting the length of the linked list.
  • n space-separated integers denoting elements of the linked list.
  • An integer ‘x’ denoting the xth element from the end to be deleted.

Output Format

For each test case, a line which contains space-separated integers denoting the elements of the resultant link list.

Sample Input

2
3
3 4 5
2
3
1 0 1
1

Expected Output

3 5
1 0

Constraints

1 <= T <= 100
1 <= n <= 104
1 <= x <= n
1 <= element <= 105

Editorial Link: Editorial