import heapq
from collections import Counter

def func(nums, k):
    count = Counter()
    for num in nums:
        count[num] += 1
    return heapq.nlargest(k, count.keys(), key=lambda x: count[x])