Code
The highlighted line runs next. The pill shows the live values in the running call.
Cost
Work done so far, and how the three solutions compare
Array and counts
The value in play is highlighted in both
The highlighted line runs next. The pill shows the live values in the running call.
Work done so far, and how the three solutions compare
The value in play is highlighted in both
Keyboard: ← → step, Space play or pause. Up to 12 numbers between -99 and 99; the top k must be unique (no tie at the cut-off), as the problem promises. The count map is walked in first-seen order here (like Python's dict); Java's HashMap and C++'s unordered_map may visit values in another order, which can change the order of the result but not its contents.