Handle Score
@Ibrahim Nash 6381
@blackshadows 6329
@mb1973 5388
@Quandray 5231
@akhayrutdinov 5111
@saiujwal13083 4510
@sanjay05 3762
@marius_valentin_dragoi 3522
@sushant_a 3459
@verma_ji 3357
@KshamaGupta 3318
Complete Leaderboard
Occurence of an integer in a Linked List
Easy Accuracy: 56.23% Submissions: 31799 Points: 2

Given a singly linked list and a key, count the number of occurrences of given key in the linked list.

Example 1:

N = 7
Link List = 1->2->1->2->1->3->1
search_for = 1
Output: 4
Explanation:1 appears 4 times.

Example 2:

N = 5
Link List = 1->2->1->2->1
search_for = 3
Output: 0
Explanation:3 appears 0 times.
Your Task:
You dont need to read input or print anything. Complete the function count() which takes the head of the link list and search_for i.e- the key as input parameters and returns the count of occurrences of the given key.

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

0 ≤ N ≤ 10^4

to report an issue on this page.


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


All Submissions

My Submissions:

Login to access your submissions.

Occurence of an integer in a Linked List

Output Window