Loading problem…
You're building an analytics dashboard that shows trending products, most viewed pages, or popular content. You need to find the top K most frequently occurring items from a dataset.
Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order.
topKFrequent([1,1,1,2,2,3], 2); // [1, 2] - 1 appears 3 times, 2 appears 2 times
topKFrequent([1], 1); // [1]
topKFrequent([4,1,-1,2,-1,2,3], 2); // [-1, 2] - both appear twiceThis problem models real analytics features: