Frequent Elements

ARRAY
SORTING

Problem

Given an array nums of integers and an integer k, determine the k most frequent elements in the array. The output should be sorted by the frequency of the elements from lowest to highest. If multiple elements have the same frequency, their order in the output is not significant.

Examples

findFrequentElements([1,1,2,2,3,3,3], 1) // returns [3] // 3 is the most frequent element, appearing 3 times. findFrequentElements([2,2,1,1,3,3,3], 2) // returns [3,2]
Loading...