Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a map that counts characters.
DSA Go
count := make(map[rune]int[1])Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets [] instead of curly braces {} to initialize the map.
Trying to use parentheses () or angle brackets <> which are invalid here.
✗ Incorrect
In Go, to create an empty map, use make(map[type]type) with curly braces {} to initialize.
2fill in blank
mediumComplete the code to count each character in the string s.
DSA Go
for _, ch := range s { count[ch][1]++ }
Attempts:
3 left
💡 Hint
Common Mistakes
Using = instead of ++ which overwrites the count.
Using += without a number (like += 1) is valid but ++ is simpler here.
✗ Incorrect
To increment the count for each character, use ++ operator on the map value.
3fill in blank
hardFix the error in the code to return the first non-repeating character index or -1 if none.
DSA Go
for i, ch := range s { if count[ch] [1] 1 { return i } } return -1
Attempts:
3 left
💡 Hint
Common Mistakes
Using = which assigns instead of compares, causing a compile error.
Using > or < which changes the logic and may miss the correct character.
✗ Incorrect
To check if a character count equals 1, use the equality operator ==.
4fill in blank
hardFill both blanks to complete the function signature and variable declaration.
DSA Go
func [1](s string) int { [2] := make(map[rune]int) // rest of code }
Attempts:
3 left
💡 Hint
Common Mistakes
Using generic names like func f or variable names that don't match usage.
Naming the map something unrelated to counting.
✗ Incorrect
The function is named firstNonRepeatingChar and the map variable is named count.
5fill in blank
hardFill all three blanks to complete the loop that finds the first non-repeating character index.
DSA Go
for [1], [2] := range s { if count[[2]] == 1 { return [1] } } return -1
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing variable names inconsistently.
Returning the character instead of the index.
✗ Incorrect
Use i and ch as loop variables and return i as the index.
