Showing:
Handle Score
@Ibrahim Nash 6420
@mb1973 5642
@Quandray 5233
@akhayrutdinov 5111
@saiujwal13083 4610
@sanjay05 3762
@kirtidee18 3673
@marius_valentin_dragoi 3522
@sushant_a 3459
@verma_ji 3413
Delete keys in a Linked list
Medium Accuracy: 48.44% Submissions: 26790 Points: 4

Given a single linked list and an integer x. Your task is to complete the function deleteAllOccurances() which deletes all occurences of a key x present in the linked list. The function takes two arguments: the head of the linked list and an integer x. The function should returns the head of the modified linked list.

Example 1:

Input:
x = 4
Output:
3
2 2 1


Example 2:

Input:
x = 2
Output:
3
1 3 3
Explanation: Given number to delete is 2.
First line of output contains the
number of remaining elements in the list.
After deleting all occurrences of 2, we
have elements in the list as 1, 3, and 3.


The task is to complete the function deleteAllOccurances() which should delete all the occurrences of given number x from the list and return the head of the modified linked list.

Expected Time Complexity : O(N)
Expected Auxilliary Space : O(1)

Constraints:
1 <= size of the linkedlist <= 100
1 <= x <= N