Count Occurrences of a Target Value
EasyPractice library · +10 XParraysloopscounting
Given an array of N integers and a target integer T, count how many times T appears in the array.
Input
The first line contains two integers N and T, separated by a space. The second line contains N integers, the elements of the array, separated by spaces.
Output
Print a single integer, the count of T in the array.
Constraints
1 <= N <= 1000 -1000 <= array elements <= 1000 -1000 <= T <= 1000
Time limit 1 s (native code; slower languages get more)Memory 256 MB13 hidden tests
Example 1
Input
5 3 1 3 2 3 4
Output
2
The target value 3 appears 2 times in the array.
Example 2
Input
4 7 1 2 3 4
Output
0
The target value 7 appears 0 times in the array.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
Example 1 input
5 3 1 3 2 3 4
Example 2 input
4 7 1 2 3 4