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 Java
String result = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Using integer 1 instead of string "1".
Starting with "0" or other digits.
✗ Incorrect
The count-and-say sequence always starts with "1" as the first term.
2fill in blank
mediumComplete the code to iterate from the second term up to n in the count-and-say sequence.
DSA Java
for (int i = 2; i <= [1]; i++) {
Attempts:
3 left
💡 Hint
Common Mistakes
Using the loop variable i as the upper bound.
Using a fixed number instead of n.
✗ Incorrect
We loop from 2 to n to build each term of the sequence.
3fill in blank
hardFix the error in the code that counts consecutive characters in the current term.
DSA Java
if (currentChar == [1].charAt(j)) {
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing with result.charAt(j) which is the next term being built.
Using an undefined variable.
✗ Incorrect
We compare with the character at position j in the current term stored in temp.
4fill in blank
hardFill both blanks to append the count and character to the next term string builder.
DSA Java
sb.append([1]).append([2]);
Attempts:
3 left
💡 Hint
Common Mistakes
Appending the character before the count.
Appending wrong variables like indices.
✗ Incorrect
We append the count of characters and then the character itself to build the next term.
5fill in blank
hardFill all three blanks to update the current character, reset count, and convert StringBuilder to string.
DSA Java
currentChar = [1]; count = [2]; result = [3].toString();
Attempts:
3 left
💡 Hint
Common Mistakes
Not resetting count to 1.
Assigning result to wrong variable.
Not updating currentChar correctly.
✗ Incorrect
After appending, update currentChar to the new character, reset count to 1, and convert sb to string for the next iteration.
