Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a map that counts frequencies of characters in a string.
DSA Go
freq := make(map[[1]]int)Attempts:
3 left
💡 Hint
Common Mistakes
Using 'string' as the map key type causes counting whole substrings instead of characters.
Using 'int' or 'float64' as key types is incorrect for characters.
✗ Incorrect
In Go, strings are sequences of bytes. Using 'byte' as the key type allows counting each character's frequency.
2fill in blank
mediumComplete the code to increase the frequency count of each character in the string.
DSA Go
for i := 0; i < len(s); i++ { freq[s[[1]]]++ }
Attempts:
3 left
💡 Hint
Common Mistakes
Using a fixed index like 0 or 1 instead of the loop variable.
Using len(s) as an index causes out-of-range error.
✗ Incorrect
We use 'i' as the index to access each character in the string 's'.
3fill in blank
hardFix the error in the code that checks if two strings have the same character frequency.
DSA Go
if len(s1) != len(s2) { return false } freq := make(map[byte]int) for i := 0; i < len(s1); i++ { freq[s1[i]]++ freq[s2[[1]]]-- } for _, count := range freq { if count != 0 { return false } } return true
Attempts:
3 left
💡 Hint
Common Mistakes
Using a fixed index like 0 or 1 instead of the loop variable.
Using len(s2) as an index causes out-of-range error.
✗ Incorrect
We must use the same index 'i' to access characters in both strings to compare frequencies correctly.
4fill in blank
hardFill both blanks to create a frequency map for words longer than 3 characters.
DSA Go
freq := make(map[string]int) for _, word := range words { if len(word) [1] 3 { freq[[2]]++ } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' causes wrong filtering.
Using 'len(word)' as map key instead of 'word' causes incorrect counting.
✗ Incorrect
We check if word length is greater than 3 and then increment frequency for the word itself.
5fill in blank
hardFill all three blanks to create a frequency map of uppercase letters only.
DSA Go
freq := make(map[byte]int) for i := 0; i < len(text); i++ { ch := text[i] if ch [1] 'A' && ch [2] 'Z' { freq[[3]]++ } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' or '<' instead of '>=' or '<=' excludes boundary letters.
Using 'text[i]' instead of 'ch' is correct but less clear.
✗ Incorrect
We check if ch is between 'A' and 'Z' inclusive, then increment frequency for ch.
