A GE HealthCare Edison application receives integer-coded measurement events. Given an integer array nums and an integer k, return the k distinct values that occur most frequently.
Use frequency as the primary ordering. If two values have the same frequency, return the smaller value first. The output may contain the values in any order internally, but the final result must follow this deterministic ordering.
Implement top_k_frequent(nums, k).
nums, a non-empty list of integers, and k, an integer between 1 and the number of distinct values in nums.k distinct integers, ordered by decreasing frequency and then increasing numeric value.def top_k_frequent(nums, k):