Count Occurrences
Count Occurrences
You are given a list of N integers and one more integer X. Print how many times X appears in the list.
If X never appears, print 0.
The input has three lines: N, then the N numbers, then X.
One counter and one pass over the array is all this needs. Increase the counter only when the element equals X.
Line 1: the integer N. Line 2: N space-separated integers. Line 3: the integer X.
A single integer: how many elements equal X.
1 <= N <= 10^5, and all values are between -10^9 and 10^9
5 1 2 2 3 2 2
3
The value 2 appears at three positions.
Submit runs your code against 5 test cases — the 1 shown above plus 4 hidden ones covering the awkward cases. Run sample just tries the first example, which is usually what you want while you are still working it out.