New update is available. Click here to update.

Delete a Given Node

Posted: 2 Dec, 2020
Difficulty: Easy


Try Problem

Ninja is learning data structures and came across a doubly linked list. Now he wants to remove a particular element from the linked list. Can you help Ninja do so and return the final linked list?

Input Format:
The first line contains a single integer T, denoting the number of test cases. 

The first line of each test case contains a Linked list of length N separated by space and terminated by -1.

The second and last line contains an element that has to be removed from the linked list.
Output Format
The first and only line of each test case in the output contains the linked list after deleting the required element.
You are not required to print the expected output; it has already been taken care of. Just implement the function. If there are multiple nodes with the given value remove just the first one.
1 <= T <= 5
1 <= N <= 10^5
-10^5 <= arr[i] <= 10^5

Time Limit: 1 sec