Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare the hash map variable for grouping anagrams.
DSA C
HashMap* [1] = createHashMap(); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using generic names like 'map' or 'hashTable' which are less descriptive.
✗ Incorrect
The variable 'groupMap' is used to store groups of anagrams in the hash map.
2fill in blank
mediumComplete the code to sort the characters of the string key for grouping anagrams.
DSA C
qsort(key, strlen(key), sizeof(char), [1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a function name that does not match the expected qsort comparator signature.
✗ Incorrect
The 'cmpfunc' is the comparison function passed to qsort to sort characters.
3fill in blank
hardFix the error in the code to insert the original string into the hash map under the sorted key.
DSA C
insertHashMap([1], originalStr); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the order of arguments or missing the map variable.
✗ Incorrect
The function insertHashMap takes the map and the key to insert the original string into the group.
4fill in blank
hardFill both blanks to check if the sorted key exists in the map and then add the original string to the group.
DSA C
if (hashMapContains([1], [2])) { addToGroup([1], [2], originalStr); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the original string instead of the key for lookup.
✗ Incorrect
We check if 'groupMap' contains 'key' and then add the original string to that group.
5fill in blank
hardFill all three blanks to create a new group list for the sorted key and insert the original string.
DSA C
List* newGroup = createList(); addToList(newGroup, [1]); insertHashMap([2], [3], newGroup);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the order of arguments or inserting the wrong variables.
✗ Incorrect
We add the original string to the new group list, then insert the list into the map with the sorted key.
