All challenges

Algorithm challenge · DSA

Top K Frequent Elements

Difficulty

medium

Time

~25m

Format

Single

Grading

Auto-graded

#python#javascript#typescript#go#java#cpp#rust#dsa#hashing#heap
Mission file // read carefullymedium

Given an integer array nums and an integer k, return the k most frequent elements. The answer is unique for the given inputs; return order does not matter.

nums = [1,1,1,2,2,3], k = 2  =>  [1,2]

Build with

topKFrequent(nums: int[], k: int) → int[]
PythonJavaScriptTypeScriptGoJavaC++Rust
4 tests · 1 hidden
Auto-graded on submit
Start challenge

Sign in to save your progress.