FirstHack Learn
Log in Sign up free
← All problems

Count Occurrences

Medium 1 solved

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.

Input

Line 1: the integer N. Line 2: N space-separated integers. Line 3: the integer X.

Output

A single integer: how many elements equal X.

Constraints

1 <= N <= 10^5, and all values are between -10^9 and 10^9

Example 1
Input
5
1 2 2 3 2
2
Output
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.