""" """ import heapq from collections import Counter def top_k_frequent(nums, k): count = Counter(nums) return heapq.nlargest(k, count.keys(), key=count.get) # Example usage nums = [1, 1, 1, 2, 2, 3] k = 2 print(top_k_frequent(nums, k)) # Output: [1, 2]