""" 1207.1 - Unique Number of Occurrences - Solution 1 - Hash Map + Set """
#####################################################################################
# Imports
#####################################################################################
from typing import List
from collections import Counter
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def uniqueOccurrences(self, arr: List[int]) -> bool:
"""Unique Occurrences Function"""
count = Counter(arr)
return len(count.values()) == len(set(count.values()))
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().uniqueOccurrences([1, 2, 2, 1, 1, 3])) # True
print(Solution().uniqueOccurrences([1, 2])) # False
print(Solution().uniqueOccurrences([-3, 0, 1, -3, 1, 1, 1, -3, 10, 0])) # True
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()
""" 1207.2 - Unique Number of Occurrences - Solution 2 - Manual Dictionary + Set Check """
#####################################################################################
# Imports
#####################################################################################
from typing import List
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def uniqueOccurrences(self, arr: List[int]) -> bool:
"""Unique Occurrences Function"""
freq = {}
for num in arr:
freq[num] = freq.get(num, 0) + 1
seen = set()
for count in freq.values():
if count in seen:
return False
seen.add(count)
return True
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().uniqueOccurrences([1, 2, 2, 1, 1, 3])) # True
print(Solution().uniqueOccurrences([1, 2])) # False
print(Solution().uniqueOccurrences([-3, 0, 1, -3, 1, 1, 1, -3, 10, 0])) # True
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()