Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the count array with zeros.
DSA Go
count := make([]int, [1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using length of input array instead of max+1 for count array size.
Setting count array size to zero.
✗ Incorrect
The count array size must be max+1 to cover all values from 0 to max.
2fill in blank
mediumComplete the code to count the occurrences of each element in arr.
DSA Go
for _, num := range arr { count[[1]]++ }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using loop index i instead of element num.
Using count or arr as index.
✗ Incorrect
We increment count at index num for each element num in arr.
3fill in blank
hardFix the error in updating the count array to cumulative counts.
DSA Go
for i := 1; i < len(count); i++ { count[i] = count[i] [1] count[i-1] }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction instead of addition.
Using multiplication or division.
✗ Incorrect
We add previous count to current to get cumulative counts.
4fill in blank
hardFill both blanks to place elements in output array in correct order.
DSA Go
for i := len(arr) - 1; i >= 0; i-- { output[count[arr[i]][1]] = arr[i] count[arr[i]][2] }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using +1 instead of -1 for index.
Incrementing count instead of decrementing.
✗ Incorrect
We place element at count[arr[i]]-1 index and then decrement count[arr[i]].
5fill in blank
hardFill all three blanks to copy sorted elements back to original array.
DSA Go
for i := 0; i < len(arr); i++ { arr[i] = output[[1]] [2] := i [3]++ }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names.
Not incrementing index.
✗ Incorrect
We copy output[i] to arr[i], declare index = i, then increment index.