How do you ensure that your code is maintainable and scalable?
For this hands-on exercise, implement a function that returns the k most frequent integers while keeping the design modular, readable, and efficient. When frequencies tie, return the smaller integer first. Return results ordered by decreasing frequency, then increasing value.
The function accepts a list of integers and k, and returns a list of at most k integers. Empty input or k = 0 returns an empty list.
def top_k_frequent(nums, k):