All lessons

2. Arrays & Hashing

Frequency counting

0 of 5 activities0%

Reading 1

Count, then decide

Open

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

Open

Two words are anagrams if they have

Fill in 3

Mode

Open

The value that appears most often is called the

Try it 4

Char counts

Open

Count letters in a word.

main.cpp
Loading editor…
Output will appear here.

Assignment 5

Count of x

Open

Read n, then n ints, then x. Print how many times x appears.

main.cpp
Loading editor…