Leaderboard
Showing:
Handle Score
@Ibrahim Nash 6420
@blackshadows 6380
@mb1973 5642
@Quandray 5233
@akhayrutdinov 5111
@saiujwal13083 4610
@sanjay05 3762
@kirtidee18 3673
@marius_valentin_dragoi 3522
@sushant_a 3459
@verma_ji 3413
Complete Leaderboard
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:
LinkedList = 2->2->1->4->4
x = 4
Output: 
3
2 2 1 

Example 2:

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.

 

Your Task:
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

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Delete keys in a Linked list

Output Window