5 kyu

Cream of the crop

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

Stats:

CreatedNov 29, 2016
PublishedNov 29, 2016
Warriors Trained200
Total Skips5
Total Code Submissions756
Total Times Completed50
JavaScript Completions50
Total Stars11
% of votes with a positive feedback rating93% of 23
Total "Very Satisfied" Votes20
Total "Somewhat Satisfied" Votes3
Total "Not Satisfied" Votes0
Total Rank Assessments3
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
5 kyu
Ad
Contributors
  • joh_pot Avatar
  • smile67 Avatar
Ad