Count Occurrences (Set 1)

Easy

Given an array of integers nums and a target, return how many times target appears in the array.

Count Occurrences (Set 1) — the data. This set runs 4 cases: nums holds arrays of 4–11 items, with values from 1 to 5; target ranges over 2–5. The hidden cases are the largest of the set.

Example 1

countOccurrences()
Input
nums = [2, 2, 4, 3], target = 3
Output
1

Why

`countOccurrences` returns `1` for this input.

Example 2

countOccurrences()
Input
nums = [1, 3, 4, 2], target = 2
Output
1

Why

`countOccurrences` returns `1` for this input.
Constraints
1 <= nums.length <= 10^5
-10^4 <= nums[i], target <= 10^4
Every case in this set must pass: the first two are visible on Run, the last two unlock on Submit.

Topics

ArraysCounting

Implement countOccurrences in the editor and return the answer — printing it is never graded.