All lessonsOpen Open Open Open Open
2. Arrays & Hashing
Frequency counting
0 of 5 activities0%
Reading 1
Count, then decide
Many problems reduce to “how many times does each value appear?”
For limited alphabets, an int freq[256] array works. For arbitrary ints, use unordered_map.
Anagrams: two strings have the same character frequencies.
int freq[26]={0};
for (char c: s) freq[c-'a']++;Check 2
Anagram idea
Two words are anagrams if they have
Fill in 3
Mode
Try it 4
Char counts
Count letters in a word.
main.cpp
Loading editor…
Output will appear here.
Assignment 5
Count of x
Read n, then n ints, then x. Print how many times x appears.
main.cpp
Loading editor…