Practice

Count Occurrences

HARDArrays

Read N (1 ≤ N ≤ 10), then N integers, then a target value. Output how many times the target appears in the array.

Input: N, then N integers, then the target. Output: The count of occurrences.

Example:

Input:  5
        3  5  3  5  3
        3
Output: 3

Sample Test Cases

Test 1: Target appears 3 times
Inputs: 5, 3, 5, 3, 5, 3, 3
Expected: 3
Test 2: Target appears twice
Inputs: 4, 1, 2, 1, 3, 1
Expected: 2

Premium Question

This question needs a paid plan — upgrade, or join a class from a teacher who has one. You can read the description and sample tests, but grading is locked.

Sign in to get started