Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare the counting array with the correct size.
DSA C
int count[[1]];Attempts:
3 left
💡 Hint
Common Mistakes
Using max instead of max + 1 causes out-of-bound errors.
Using n (array length) instead of max + 1.
✗ Incorrect
The counting array size must be max + 1 to include all values from 0 to max.
2fill in blank
mediumComplete the code to initialize the counting array elements to zero.
DSA C
for (int i = 0; i < [1]; i++) { count[i] = 0; }
Attempts:
3 left
💡 Hint
Common Mistakes
Looping only n times instead of max + 1.
Looping to max instead of max + 1.
✗ Incorrect
We initialize all count elements from 0 to max inclusive, so loop runs max + 1 times.
3fill in blank
hardFix the error in the counting step to correctly count occurrences.
DSA C
for (int i = 0; i < n; i++) { count[[1]]++; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using i as index increments wrong count.
Using count[i] as index causes errors.
✗ Incorrect
We increment count at index arr[i] to count how many times each value appears.
4fill in blank
hardFill both blanks to compute the cumulative count correctly.
DSA C
for (int i = 1; i < [1]; i++) { count[i] = count[i] [2] count[i - 1]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction instead of addition.
Looping only to max instead of max + 1.
✗ Incorrect
Loop runs from 1 to max + 1 to update counts cumulatively by adding previous count.
5fill in blank
hardFill all three blanks to place elements in output array correctly.
DSA C
for (int i = n - 1; i >= 0; i--) { output[count[[1]] - 1] = [2][i]; count[[3]]--; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using i instead of arr[i] as index.
Decrementing count[i] instead of count[arr[i]].
✗ Incorrect
We use arr[i] as index for count and to place in output, then decrement count[arr[i]].
