Given an array of integers arr, return True if the number of occurrences of each value in the array is unique, or False otherwise.
Function Signature
def unique_occurrences(arr: list[int]) -> bool:
Rules
-
Count how many times each distinct value appears in
arr
. Return
True
exactly when no two different values have the same count.
-
An array with a single distinct value always returns
True
.
Constraints
-
1 <= len(arr) <= 1000
-
-1000 <= arr[i] <= 1000
Examples
Input: arr = [1,2,2,1,1,3]
Output: True
The value 1 has 3 occurrences, 2 has 2 occurrences, and 3 has 1 occurrence. The counts 3, 2 and 1 are all different.
Input: arr = [1,2]
Output: False
The values 1 and 2 each have 1 occurrence, so two values share the count 1.
Input: arr = [-5,0,-5,0,-5,8]
Output: True
The value -5 appears 3 times, 0 appears 2 times, and 8 appears once. The counts 3, 2 and 1 are all different.