Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the map for grouping anagrams.
DSA Go
anagramMap := map[string][]string[1]Attempts:
3 left
💡 Hint
Common Mistakes
Using make() syntax.
Using square brackets [] instead of {}.
✗ Incorrect
In Go, to create an empty map using a map literal, use map[keyType]valueType{} with {} inside.
2fill in blank
mediumComplete the code to sort the characters of the string key.
DSA Go
keyChars := []rune(word)
sort.Slice(keyChars, func(i, j int) bool { return keyChars[i][1] keyChars[j] })Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' which sorts in descending order.
Using equality operators which do not sort.
✗ Incorrect
To sort characters in ascending order, use less-than operator '<' in the comparison function.
3fill in blank
hardFix the error in appending the word to the map value slice.
DSA Go
anagramMap[key] = append(anagramMap[key], [1])Attempts:
3 left
💡 Hint
Common Mistakes
Appending the key instead of the word.
Appending the map or an undefined variable.
✗ Incorrect
We append the original word to the slice for the sorted key, so 'word' is correct.
4fill in blank
hardComplete the code to append the group slice to the result.
DSA Go
for _, group := range anagramMap { result = append(result, [1]) }
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to convert group slice to string.
Using break which stops the loop early.
✗ Incorrect
Append the group slice directly as `append(result, group)`. No conversion to string is needed since `result` is `[][]string` and `group` is `[]string`.
5fill in blank
hardFill all three blanks to complete the function signature, initialize result slice, and return it.
DSA Go
func groupAnagrams([1] []string) [][]string { result := make([][]string, 0) // ... code to fill anagramMap ... return [2] } // Usage: // grouped := groupAnagrams([3])
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong parameter names.
Returning wrong variable.
Incorrect example input format.
✗ Incorrect
The function parameter name is 'strs', the result slice is named 'result', and the example input is the given slice of strings.
