1/6
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
Creating Hashmap
unordered_map<int, int> freq;
Count Numbers
unordered_map<int, int> freq;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
freq[x]++;
}
Get Count of a Number
cout << freq[x];
Loop Through Hash Map
for (auto item : freq) {
cout << item.first << " " << item.second << "\n";
}
Most common
std::unordered_map<int, int> counts; int max_freq = 0; int most_common = -1; for (int num : vec) { counts[num]++; if (counts[num] > max_freq) { max_freq = counts[num]; most_common = num;
Insert Into Set
name.insert(x);
Check If Something Exists
if (seen.count(x))