Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare the hash map that groups anagrams.
DSA C++
unordered_map<string, vector<string>> [1];Attempts:
3 left
💡 Hint
Common Mistakes
Using generic names like 'hashMap' which are less descriptive.
Using names that do not relate to grouping anagrams.
✗ Incorrect
The variable name 'anagramGroups' clearly represents the purpose of the hash map to group anagrams.
2fill in blank
mediumComplete the code to sort the string to use as a key for grouping anagrams.
DSA C++
string key = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Trying to assign the result of sort() directly to a string variable.
Using an undefined variable name.
✗ Incorrect
We first assign the original word to 'key' before sorting it. The sorting happens in the next line.
3fill in blank
hardFix the error in sorting the string key.
DSA C++
sort([1].begin(), [1].end());
Attempts:
3 left
💡 Hint
Common Mistakes
Sorting the original word instead of the key.
Using an undefined variable.
✗ Incorrect
We sort the 'key' string to get the sorted version used as the hash map key.
4fill in blank
hardFill both blanks to insert the original word into the correct group in the hash map.
DSA C++
anagramGroups[[1]].[2](word);
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'insert' which is not a vector method for adding at the end.
Using the original word as the map key instead of the sorted key.
✗ Incorrect
We use the sorted 'key' to access the vector and 'push_back' to add the original word.
5fill in blank
hardFill all three blanks to create the final result vector from the hash map.
DSA C++
vector<vector<string>> result; for (auto& [1] : anagramGroups) { result.[2]([1].[3]); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'first' instead of 'second' to access the vector.
Using incorrect variable names in the loop.
✗ Incorrect
We iterate over each map entry named 'entry', then push_back the vector stored in entry.second into result.
