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.
Input: LinkedList = 2->2->1->4->4 x = 4 Output: 3 2 2 1
Input: LinkedList = 1->2->2->3->2->3 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)
1 <= size of the linkedlist <= 100
1 <= x <= N
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?Yes