Count Occurrences of a Target - I
You are given an integer array arr of size N and a target value. Count how many elements equal the target and return the count. Use a direct traversal. Return 0 when the target does not appear in the array.
Example 1:
Input: arr = [7, 3, 5, 4, 3, 7], target = 7
Output: 2
Explanation: 7 occurs 2 times in the array
Example 2:
Input: arr = [-1, -1, -1, -1, 3, 7], target = -1
Output: 4
Explanation: -1 occurs 4 times in the array
Now Your Turn!
Pick the correct output for the given inputInput: arr = [0, 0, 0, 3, 3, 3, 3], target = 0
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
1 <= n <= 105
-109 <= arr[i] <= 109
-109 <= target <= 109