Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if a word starts with the given prefix.
DSA Go
if strings.[1](word, prefix) { return true } else { return false }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings.Contains instead of strings.HasPrefix
Using strings.Index which returns position, not boolean
✗ Incorrect
The strings.HasPrefix function checks if a string starts with the given prefix.
2fill in blank
mediumComplete the code to iterate over all words in the list.
DSA Go
for [1] := 0; i < len(words); i++ { word := words[i] }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable different from the one in the loop condition
Using a variable not declared in the loop
✗ Incorrect
The variable i is commonly used as the index in loops.
3fill in blank
hardFix the error in the code to correctly count words with the prefix.
DSA Go
count := 0 for _, word := range words { if strings.HasPrefix(word, prefix) { count [1] 1 } } return count
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' which overwrites count
Using '-=' which decreases count
✗ Incorrect
Use count += 1 to increase the count by one each time a word matches.
4fill in blank
hardFill both blanks to create a map of words and their prefix match status.
DSA Go
result := make(map[string]bool) for _, [1] := range words { result[word] = strings.[2](word, prefix) } return result
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using index variable instead of word
Using strings.Contains instead of strings.HasPrefix
✗ Incorrect
Use word to iterate and strings.HasPrefix to check prefix.
5fill in blank
hardFill all three blanks to build a prefix count map for a list of words.
DSA Go
prefixCount := make(map[string]int) for _, word := range words { for i := 1; i <= len(word); i++ { prefix := word[:[1]] prefixCount[prefix] [2] [3] 1 } } return prefixCount
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong slice index
Using '=' instead of '+=' for map update
Using '-' instead of '+' for increment
✗ Incorrect
Use i to slice prefixes, += to add counts, and + to increment.