Given a singly linked list and a key, count number of occurrences of given key in linked list. For example, if given linked list is 1->2->1->2->1->3->1 and given key is 1, then output should be 4.
1. Initialize count as zero. 2. Loop through each element of linked list: a) If element data is equal to the passed number then increment the count. 3. Return count.
count of 1 is 3
Time Complexity: O(n)
Auxiliary Space: O(1)