Count Distinct Values
MediumPractice library · +20 XPhash mapcountingfrequency
Given a list of N integers, count how many integers appear exactly once in the list. The order of integers in the input does not matter for the counting, only the final frequencies.
Input
The first line contains an integer N, the number of elements. The second line contains N integers, separated by spaces.
Output
Print a single integer: the count of distinct elements (elements that appear exactly once).
Constraints
1 <= N <= 200000 Each integer will be between -10^9 and 10^9.
Time limit 1 s (native code; slower languages get more)Memory 256 MB15 hidden tests
Example 1
Input
7 1 2 3 1 2 4 5
Output
3
Numbers 3, 4, and 5 appear exactly once.
Example 2
Input
5 10 10 10 10 10
Output
0
No number appears exactly once.
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
7 1 2 3 1 2 4 5
Example 2 input
5 10 10 10 10 10