Delete All Occurrences of a Key in a Doubly Linked List
Remove every node containing a given value from a doubly linked list.
Input format
The first line contains N and X. The second line contains the N node values of a doubly linked list.
Output format
Remove every node whose value equals X and print the remaining list (or -1 if it becomes empty).
Constraints
- Values fit in a 64-bit signed integer
- Trailing whitespace and a trailing newline are ignored by the judge
Read from stdin, write to stdout. Sample cases below show the exact format.
Sample cases
Example 1
Input
5 2
1 2 3 2 4Expected output
1 3 4Example 2
Input
3 7
7 7 7Expected output
-1