Problem of the day
A doubly-linked list is a data structure that consists of sequentially linked nodes, and the nodes have reference to both the previous and the next nodes in the sequence of nodes.
You’re given a doubly-linked list and a key 'k'.
Delete all the nodes having data equal to ‘k’.
Input: Linked List: 10 <-> 4 <-> 10 <-> 3 <-> 5 <-> 20 <-> 10 and ‘k’ = 10
Output: Modified Linked List: 4 <-> 3 <-> 5 <-> 20
Explanation: All the nodes having ‘data’ = 10 are removed from the linked list.
The first line contains an integer ‘n’, the number of nodes in the linked list.
The next line contains ‘n’ numbers, the linked list.
The third line contains an integer ‘k’, the key whose occurrences are to be removed.
Print the modified linked list.
You do not need to print anything; it has already been taken care of. Just implement the given function.
7
10 4 10 3 5 20 10
10
4 3 5 20
All the nodes having ‘data’ = 10 are removed from the linked list.
7
10 4 10 3 5 20 10
30
10 4 10 3 5 20 10
The linked list does not have any node with ‘data’ = 30. So the linked list is unchanged.
The expected time complexity is O(‘n’).
0 <= ‘n’ <= 100000
1 <= ‘data’ in any node <= 10^9
1 <= ‘k’ <= 10^9