Unique Number of Occurrences

Easy

Return true when every distinct value in arr occurs a different number of times.

Example 1

uniqueOccurrences()
Input
arr = [1,2,2,1,1,3]
Output
true

Why

1 → three times, 2 → twice, 3 → once.

Example 2

uniqueOccurrences()
Input
arr = [1,2]
Output
false

Why

Both values occur once.
Constraints
1 <= arr.length <= 1000
-1000 <= arr[i] <= 1000

Topics

ArraysHash Table

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