Unique number of occurrences
November 30, 2022
array-and-hashmapProblem URL: Unique number of occurrences
We will count the number of occurrences of each number in the array. We will then check if the number of occurrences is unique using a hash set.
class Solution:
def uniqueOccurrences(self, arr: List[int]) -> bool:
count = collections.Counter(arr)
return len(count.values()) == len(set(count.values()))
Time complexity: O(n)
, n is the length of the array
Space complexity: O(n)