5 kyu
Cream of the crop
50joh_pot
Description:
Write
function topFrequent(nums, k){}
that takes in array of numbers nums
and a number k
and returns an array with the k
most frequent numbers in nums
For example
topFrequent([1, 1, 1, 5, 5, 2, 2, 2], 1) === [1]
topFrequent([1, 1, 1, 5, 5, 2, 2, 2], 2) === [1, 2]
topFrequent([1, 1, 1, 5, 5, 2, 2, 3], 3) === [1, 5, 2] // When nums have the same frequency, return it based on index
topFrequent([9, 8, 7, 6, 5, 4, 3, 2, 1], 100) === [9, 8, 7, 6, 5, 4, 3, 2, 1]
// k is larger than nums length, so everything is returned
NOTE: Performance is critical. There are large tests.
Performance
Algorithms
Similar Kata:
Stats:
Created | Nov 29, 2016 |
Published | Nov 29, 2016 |
Warriors Trained | 200 |
Total Skips | 5 |
Total Code Submissions | 756 |
Total Times Completed | 50 |
JavaScript Completions | 50 |
Total Stars | 11 |
% of votes with a positive feedback rating | 93% of 23 |
Total "Very Satisfied" Votes | 20 |
Total "Somewhat Satisfied" Votes | 3 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 3 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 5 kyu |