Loading
Loading
An error dashboard needs the k error codes that occurred most often.
Return those codes sorted by frequency, highest first. When two codes tie, the smaller code comes first.
codes = [1, 1, 1, 2, 2, 3], k = 2counts1 → 3, 2 → 2, 3 → 1top 21 (3 times), 2 (2 times)[1, 2]Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(n + m log k) time · O(m) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
1 occurs three times, 2 twice.
Example 2
Example 3
Tied at one occurrence each, so the smaller code leads.