Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if two strings have the same length.
DSA Go
if len(s1) [1] len(s2) { return false }
Attempts:
3 left
š” Hint
Common Mistakes
Using '==' instead of '!=' causes incorrect logic.
Using '>' or '<' does not correctly check for length equality.
ā Incorrect
We return false if the lengths are not equal, so the operator must be '!='.
2fill in blank
mediumComplete the code to count characters in the first string using a map.
DSA Go
count := make(map[rune]int) for _, ch := range s1 { count[ch] [1] 1 }
Attempts:
3 left
š” Hint
Common Mistakes
Using '=' resets the count instead of incrementing.
Using '-=' or '*=' changes the count incorrectly.
ā Incorrect
We add 1 to the count for each character, so '+=' is correct.
3fill in blank
hardFix the error in decreasing the count for characters in the second string.
DSA Go
for _, ch := range s2 { count[ch] [1] 1 if count[ch] < 0 { return false } }
Attempts:
3 left
š” Hint
Common Mistakes
Using '+=' increases count incorrectly.
Using '=' resets count causing wrong results.
ā Incorrect
We subtract 1 for each character in the second string, so '-=' is correct.
4fill in blank
hardFill both blanks to check if all counts are zero after processing both strings.
DSA Go
for _, v := range count { if v [1] 0 { return false } } return [2]
Attempts:
3 left
š” Hint
Common Mistakes
Using '==' instead of '!=' in the if condition causes wrong logic.
Returning false instead of true at the end.
ā Incorrect
If any count is not zero, return false; otherwise, return true.
5fill in blank
hardFill all three blanks to complete the anagram check function using sorting.
DSA Go
func isAnagramSort(s1, s2 string) bool {
if len(s1) [1] len(s2) {
return false
}
a := []rune(s1)
b := []rune(s2)
sort.[2](a)
sort.[2](b)
return string(a) [3] string(b)
}Attempts:
3 left
š” Hint
Common Mistakes
Using '==' instead of '!=' for length check.
Using wrong sort function name.
Using '=' instead of '==' for string comparison.
ā Incorrect
Check length inequality with '!=', sort slices with 'Sort', and compare strings with '=='.
