Top K frequent elements
Asked in the Online Assessment stage. Passed 21/21 test cases.
Given an integer array nums and integer k, return the k values with the highest frequencies. Return results ordered by decreasing frequency; break frequency ties by ascending numeric value.
Implement top_k_frequent(nums, k). The input is a non-empty list of integers and a valid integer k. Return a list containing exactly k distinct integers.
def top_k_frequent(nums, k):