Bird
0
0
DSA Cprogramming~10 mins

First Non Repeating Character Using Hash 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 declare the frequency array for all ASCII characters.

DSA C
int freq[[1]] = {0};
Drag options to blanks, or click blank then click option'
A256
B64
C128
D512
Attempts:
3 left
💡 Hint
Common Mistakes
Using 128 instead of 256 causes out-of-bound errors for extended ASCII characters.
2fill in blank
medium

Complete the code to increment the frequency count of each character in the string.

DSA C
freq[(unsigned char)str[[1]]]++;
Drag options to blanks, or click blank then click option'
Aindex
Bj
Ck
Di
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable not declared or not used in the loop.
3fill in blank
hard

Fix the error in the loop condition to find the first non-repeating character.

DSA C
for (int [1] = 0; str[i] != '\0'; i++) {
Drag options to blanks, or click blank then click option'
Ak
Bj
Ci
Dindex
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variables in initialization and condition causes errors.
4fill in blank
hard

Fill both blanks to check if the character frequency is 1 and return it.

DSA C
if (freq[(unsigned char)str[[1]]] [2] 1) {
    return str[i];
}
Drag options to blanks, or click blank then click option'
Ai
B==
C!=
Dj
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' causes wrong character to be returned.
5fill in blank
hard

Fill all three blanks to complete the function that returns the first non-repeating character or '_' if none found.

DSA C
char firstNonRepeatingChar(char *str) {
    int freq[[1]] = {0};
    for (int [2] = 0; str[[2]] != '\0'; [2]++) {
        freq[(unsigned char)str[[2]]]++;
    }
    for (int i = 0; str[i] != '\0'; i++) {
        if (freq[(unsigned char)str[i]] [3] 1) {
            return str[i];
        }
    }
    return '_';
}
Drag options to blanks, or click blank then click option'
A256
Bi
C==
Dj
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong array size, wrong loop variable, or wrong comparison operator.