SDE & MLE Prep

1207. Unique Number of Occurrences

Problem

Return true if every distinct value in arr occurs a different number of times than every other value.

Example: [1,2,2,1,1,3] → true (counts 3, 2, 1); [1,2] → false

Count each value, then check that no two values share a count: the number of distinct counts must equal the number of distinct values.

Complexity: O(n).

class Solution:
    def uniqueOccurrences(self, arr: List[int]) -> bool:
        counts = list(Counter(arr).values())
        return len(counts) == len(set(counts))