Inc.'s ranking pipeline receives an integer array of event values. Return the k values that occur most frequently.
Count each distinct value, then select the k highest-frequency values. If two values have the same frequency, return the smaller value first. The final result must therefore be ordered by decreasing frequency, followed by increasing numeric value.
Implement top_k_frequent(nums, k). The input nums is a list of integers, and k is an integer. Return a list containing exactly k distinct integers, ordered according to the rules above.
def top_k_frequent(nums, k):