Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning "0" instead of "1" as the first term.
Using numeric 1 instead of string "1".
✗ Incorrect
The first term in the count and say sequence is always "1".
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using i-- which causes infinite loop.
Skipping characters by incrementing by 2.
✗ Incorrect
We increment i by 1 to move through each character in the string.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing prev[j] with itself causing infinite loop.
Using prev[i+1] which may go out of bounds.
✗ Incorrect
We compare characters at j with the character at i to count repeats.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Appending j instead of count.
Appending character at j instead of i.
✗ Incorrect
We append the count and the character at position i to the result.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Resetting count to 0 causing incorrect counts.
Not updating i and j correctly causing infinite loops.
✗ Incorrect
Set i and j to j to move forward, reset count to 1 for next group.
