Top K Frequent Elements
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]
topKFrequent([1], 1); // [1]Loading compiler resources...
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]
topKFrequent([1], 1); // [1]Run your code to see results.
This interactive challenge requires a DeepFrontend Pro membership. Get instant access to write, execute, test, and view verified solution code directly in your browser.
Regional pricing available • Instant access
Stuck? This challenge exercises: