Delete Node From Linked List

Easy

Delete a given node from a singly-linked list. You do not have access to the head of the list. Also, the node to be deleted is not the tail of the linked list.

Example 1:

1→2→3→4

Deleting 2nd node, we get

1→3→4

Example 2:

1→3→4→1

Deleting 3rd node, we get

1→3→1

Testing

Input Format

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

For each test case the input has three lines:

  • A number ‘n’, denoting the length of the linked list.
  • n space-separated integers denoting elements of the linked list.
  • A number ‘c’ denoting the position of the linked list node which is to be deleted.

Output Format

For each test case, the output has one line with n-1 space-separated integers denoting the elements of the resultant linked list.

Sample Input

2
4
1 2 3 4
3
3
4 5 6
2

Expected Output

1 2 4
4 6

Constraints

1 <= T <= 100
1 <= n <= 1000
1 <= element <= 105

Editorial Link: Editorial