class Solution {
public:
vector<int> topKFrequent(vector<int>& nums, int k) {
unordered_map<int, int> hashing;
for (auto elm : nums) hashing[elm]++;
int n = nums.size();
vector<int> count(n + 1, 0);
for (auto &p : hashing) count[p.second]++;
int i = n, t = 0;
while (t < k) t += count[i--];
vector<int> res;
for (auto &p : hashing) {
if (p.second > i) res.push_back(p.first);
}
return res;
}
};