Remove Nodes with Specific Value from Linked List
You are provided with a singly linked list consisting of integer values and an integer 'K'. Your task is to eliminate all nodes from the linked list that have a value equal to 'K'.
A singly linked list is a linear data structure that allows traversal in one direction, from the head to the tail. Each node consists of data and a reference to the next node.
Example:
Input:
3
1 2 3 4 -1
2
4 4 4 4 -1
4
5 5 -1
5
Output:
1 3 4
EMPTY
5
Explanation:
In the first test case, node with value 2 is removed: [1, 3, 4]. In the second, all nodes are removed because all have the value 4, resulting in an empty list. In the third, no nodes have the value 5, so the list remains [5].
Constraints:
1 <= T <= 10
1 <= N <= 10^5
0 <= node.data <= 10^9
andnode.data != -1
0 <= K <= 10^9
Note:
You are not required to print anything; the function is provided for implementation.
Remove nodes with specific value from a singly linked list.
Traverse the linked list and remove nodes with value equal to 'K'.
Update the references of the previous node to skip the removed node.
Handle ...read more
Top Freshworks Software Engineer interview questions & answers
Popular interview questions of Software Engineer
Reviews
Interviews
Salaries
Users/Month