Complete the code to initialize the count array with zeros.
const count = new Array(max + 1).fill([1]);
Counting sort uses a count array initialized with zeros to store frequencies.
Complete the code to count the frequency of each element in the input array.
for (let i = 0; i < arr.length; i++) { count[arr[i]] [1]; }
We increment the count for each element found in the input array.
Fix the error in the code to compute the cumulative count correctly.
for (let i = 1; i <= max; i++) { count[i] = count[i] [1] count[i - 1]; }
Cumulative count is the sum of current count and previous counts.
Fill both blanks to place elements in the output array in stable order.
for (let i = arr.length - 1; i >= 0; i--) { output[count[arr[i]] [1]] = arr[i]; count[arr[i]] [2]; }
We place the element at index count[element] - 1 and then decrement the count.
Fill all three blanks to copy the sorted output back to the original array.
for (let i = 0; i < arr.length; ) { arr[[1]] = output[[2]]; [3]; }
We copy each element from output to arr using index i and increment i.
