from collections import Counter
import heapq

def func(nums, k):
    counts = Counter(nums)
    if k <= 0 or not counts:
        return []
    return heapq.nlargest(k, counts.keys(), key=counts.get)