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 Typescript
let result = "[1]";
Attempts:
3 left
💡 Hint
Common Mistakes
Starting with "0" instead of "1".
Using multiple digits as the first term.
✗ Incorrect
The count and say sequence always starts with the string "1" as the first term.
2fill in blank
mediumComplete the code to iterate through the current term characters.
DSA Typescript
for (let i = 0; i < current.length; [1]) {
Attempts:
3 left
💡 Hint
Common Mistakes
Decrementing the index causing infinite loop.
Skipping characters by incrementing by 2.
✗ Incorrect
We increment i by 1 to move through each character in the string one by one.
3fill in blank
hardFix the error in the condition to check if the next character is the same as the current.
DSA Typescript
while (j < current.length && current[j] [1] current[i]) {
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' which breaks counting repeated characters.
Using greater or less than which is not meaningful for characters here.
✗ Incorrect
We want to continue while the next character is equal to the current character to count repeats.
4fill in blank
hardFill both blanks to build the next term by appending count and character.
DSA Typescript
nextTerm += [1] + [2];
Attempts:
3 left
💡 Hint
Common Mistakes
Appending count as a number causing type errors.
Appending the string "count" instead of the variable.
✗ Incorrect
We convert count to string and append the current character to form the next term.
5fill in blank
hardFill all three blanks to complete the count and say function loop.
DSA Typescript
for (let [1] = 1; [2] <= n; [3]++) { let nextTerm = ""; // build nextTerm here result = nextTerm; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in the loop parts.
Using 'j' which is not declared for this loop.
✗ Incorrect
The loop variable is 'i' starting at 1, running until i <= n, incrementing i by 1 each time.
