Algorithm · Amazon · Hard
Implement a function topKFrequent(nums, k) that takes an integer array nums and an integer k, and returns the k values that occur most often in nums. If multiple values share the same frequency, make the tie behavior explicit: state whether any choice of k values with the highest frequencies is acceptable, or whether a deterministic tie-break is required. Your work should cover the following points: Contrast three strategies for selecting the top k: sorting all elements,…