FunctionRacerProblemsRace

Top K Frequent Elements

EasyHash mapsPython, JavaScript, TypeScript, Java, C++

Return the k values that appear most often in nums, ordered from most frequent to least frequent.

The tests never have a tie that would change which values make the top k or their order.

Example 1

nums [1,1,1,2,2,3]
k 2
returns [1,2]

1 appears 3 times and 2 appears twice.

Example 2

nums [4]
k 1
returns [4]

Only one value.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Hash maps problems