from collections import defaultdict
from typing import Dict, List


class Solution:
    def topKFrequent(self, nums: List[int], k: int) -> List[int]:
        frequency_hashmap: Dict[int, int] = defaultdict(int)
        result_hasmap: Dict[int, int] = defaultdict(int)
        for nums_entry in nums:
            frequency_hashmap[nums_entry] += 1
            if not result_hasmap[frequency_hashmap[nums_entry]]:
                result_hasmap[frequency_hashmap[nums_entry]] = nums_entry
        return result_hasmap
        # return list(result_hasmap.values())[-k:]


s = Solution()
# print(s.topKFrequent(nums=[1, 2, 2, 2, 5, 5, 5, 5, 3, 3, 3, 3, 3], k=2))
# print(s.topKFrequent(nums=[1, 2, 2, 3, 3, 3], k=2))
print(s.topKFrequent(nums=[1, 1, 1, 2, 2, 3], k=2))
# print(s.topKFrequent(nums=[7, 7], k=1))
