Bird
0
0
DSA Cprogramming~10 mins

Anagram Check Techniques in DSA C - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to compare the lengths of two strings for anagram check.

DSA C
if (strlen(str1) [1] strlen(str2)) {
    return 0; // Not anagrams
}
Drag options to blanks, or click blank then click option'
A==
B<
C!=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '!=' causes the function to wrongly reject anagrams.
Using '>' or '<' does not correctly check length equality.
2fill in blank
medium

Complete the code to initialize the frequency array for counting characters.

DSA C
int count[256] = {0};
for (int i = 0; i < [1]; i++) {
    count[(unsigned char)str1[i]]++;
    count[(unsigned char)str2[i]]--;
}
Drag options to blanks, or click blank then click option'
Astrlen(str2)
Bstrlen(str1)
Csizeof(str1)
Dsizeof(str2)
Attempts:
3 left
💡 Hint
Common Mistakes
Using sizeof on a pointer instead of strlen causes wrong loop bounds.
Using strlen(str2) is correct but less consistent here.
3fill in blank
hard

Fix the error in the condition that checks if all counts are zero after frequency counting.

DSA C
for (int i = 0; i < 256; i++) {
    if (count[i] [1] 0) {
        return 0; // Not anagrams
    }
}
Drag options to blanks, or click blank then click option'
A!=
B==
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' causes the function to wrongly accept non-anagrams.
Using '>' or '<' does not correctly detect mismatches.
4fill in blank
hard

Fill all three blanks to complete the sorting-based anagram check.

DSA C
int compare(const void *a, const void *b) {
    return (*(char *)[1] - *(char *)[2]);
}

qsort(str1, [3], sizeof(char), compare);
Drag options to blanks, or click blank then click option'
Aa
Bb
Cstrlen(str1)
Dstrlen(str2)
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping 'a' and 'b' in subtraction reverses sorting order.
Using strlen(str2) is valid but inconsistent here.
5fill in blank
hard

Fill all three blanks to complete the final anagram check using sorted strings.

DSA C
if (strncmp(str1, str2, [1]) [2] 0) {
    return [3]; // Not anagrams
} else {
    return 1; // Anagrams
}
Drag options to blanks, or click blank then click option'
Astrlen(str1)
B!=
C0
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '!=' causes wrong anagram detection.
Returning 1 on mismatch is incorrect.