Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a hash map to count frequencies of characters.
DSA C++
std::unordered_map<char, int> freq[1];Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets [] which are for indexing, not initialization.
Using parentheses () which results in invalid syntax {()}.
Using angle brackets <> which are for template parameters.
✗ Incorrect
In C++, to declare an empty unordered_map using brace initialization, use {} for the empty initializer list.
2fill in blank
mediumComplete the code to increment the frequency count of character c in the map.
DSA C++
freq[1]++;Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses which is for function calls.
Using curly braces which is for initialization.
✗ Incorrect
To access or insert a key in unordered_map, use square brackets [].
3fill in blank
hardFix the error in the code to check if character c exists in the map.
DSA C++
if (freq.find[1] == freq.end()) { /* not found */ }
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets which is for indexing, not function call.
Using curly braces or angle brackets which are invalid here.
✗ Incorrect
The find method takes the key as an argument inside parentheses.
4fill in blank
hardFill both blanks to create a frequency map from a string s.
DSA C++
for (char [1] : s) { freq[2]++; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of square brackets for map access.
Using inconsistent variable names.
✗ Incorrect
Use 'ch' as loop variable and access freq with square brackets [ch].
5fill in blank
hardFill all three blanks to count frequencies of integers in vector nums.
DSA C++
std::unordered_map<int, int> freq; for (int [1] : nums) { freq[2]++; } int count = freq[3];
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of square brackets for map access.
Using wrong variable names or keys.
✗ Incorrect
Use 'num' as loop variable, access freq with [num], and get count of 5 with [5].
