0
0
DSA Goprogramming~10 mins

Counting Sort Algorithm in DSA Go - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A0
Blen(arr)
Cmax+1
Dlen(arr)+1
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.
2fill in blank
medium

Complete 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'
Ai
Bnum
Ccount
Darr
Attempts:
3 left
💡 Hint
Common Mistakes
Using loop index i instead of element num.
Using count or arr as index.
3fill in blank
hard

Fix 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'
A+
B-
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction instead of addition.
Using multiplication or division.
4fill in blank
hard

Fill 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'
A-1
B+1
C--
D++
Attempts:
3 left
💡 Hint
Common Mistakes
Using +1 instead of -1 for index.
Incrementing count instead of decrementing.
5fill in blank
hard

Fill 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'
Ai
Bindex
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names.
Not incrementing index.