Bird
0
0
DSA Cprogramming~10 mins

Count and Say Problem 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 initialize the first term of the count and say sequence.

DSA C
char* countAndSay(int n) {
    if (n == 1) return [1];
    // rest of the code
}
Drag options to blanks, or click blank then click option'
A"11"
B"0"
C"1"
D"2"
Attempts:
3 left
💡 Hint
Common Mistakes
Returning "0" instead of "1" as the first term.
Using numeric 1 instead of string "1".
2fill in blank
medium

Complete the code to iterate through the previous term string.

DSA C
for (int i = 0; i < strlen(prev); [1]) {
    // process characters
}
Drag options to blanks, or click blank then click option'
Ai--
Bi=0
Ci+=2
Di++
Attempts:
3 left
💡 Hint
Common Mistakes
Using i-- which causes infinite loop.
Skipping characters by incrementing by 2.
3fill in blank
hard

Fix the error in the condition to count consecutive characters.

DSA C
while (j < strlen(prev) && prev[j] == [1]) {
    count++;
    j++;
}
Drag options to blanks, or click blank then click option'
Aprev[j]
Bprev[i]
Cprev[i+1]
Dprev[j+1]
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing prev[j] with itself causing infinite loop.
Using prev[i+1] which may go out of bounds.
4fill in blank
hard

Fill both blanks to append count and character to the result string.

DSA C
sprintf(temp, "%d%c", [1], [2]);
strcat(result, temp);
Drag options to blanks, or click blank then click option'
Acount
Bprev[i]
Cj
Dcount + 1
Attempts:
3 left
💡 Hint
Common Mistakes
Appending j instead of count.
Appending character at j instead of i.
5fill in blank
hard

Fill all three blanks to update indices and prepare for next iteration.

DSA C
i = [1];
j = [2];
count = [3];
Drag options to blanks, or click blank then click option'
Aj
Bi + 1
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Resetting count to 0 causing incorrect counts.
Not updating i and j correctly causing infinite loops.