Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the current character exists in the children map.
DSA Go
if _, ok := node.children[[1]]; !ok { return false }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the whole word instead of a single character.
Using the index i directly instead of word[i].
✗ Incorrect
We use word[i] to get the current character to check in the children map.
2fill in blank
mediumComplete the code to move to the next node in the trie for the current character.
DSA Go
node = node.children[[1]] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the index i instead of the character word[i].
Using the whole word instead of a single character.
✗ Incorrect
We use word[i] to get the current character and move to its child node.
3fill in blank
hardFix the error in the return statement to check if the word ends here.
DSA Go
return node.[1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect field names like isEnd or end.
Returning the wrong property that does not indicate word end.
✗ Incorrect
The field isWord indicates if the current node marks the end of a word.
4fill in blank
hardFill both blanks to complete the for loop iterating over the word characters.
DSA Go
for [1] := 0; [2] < len(word); [1]++ { // loop body }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variables in initialization and condition.
Using variables not declared in the loop.
✗ Incorrect
The loop variable i is used consistently in initialization and condition.
5fill in blank
hardFill all three blanks to complete the search function signature and return type.
DSA Go
func (t *Trie) [1](word string) [2] { node := t.root for i := 0; i < len(word); i++ { if _, ok := node.children[word[i]]; !ok { return [3] } node = node.children[word[i]] } return node.isWord }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect function names.
Returning true instead of false when word not found.
Wrong return type.
✗ Incorrect
The function name is Search, it returns a bool, and returns false if word not found.