Problems > K Most Frequent > Editorial

K Most Frequent — Solution & Editorial

Back to the Problem

Count with a hash map, sort the (value, count) pairs by (−count, value), take K.

Complexity: O(N + D log D) for D distinct values