Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to get the maximum value in the array for Radix Sort.
DSA Rust
let max = *arr.iter().[1]().unwrap();Attempts:
3 left
💡 Hint
Common Mistakes
Using min instead of max.
Using max_by_key or max_by which require additional arguments.
✗ Incorrect
We use iter().max() to find the maximum value in the array, which is needed to know the number of digits.
2fill in blank
mediumComplete the code to extract the digit at the current place value.
DSA Rust
let digit = (num / [1]) % 10;
Attempts:
3 left
💡 Hint
Common Mistakes
Using a fixed number like 10 instead of the variable place.
Using modulo before division.
✗ Incorrect
We divide the number by the current place value (place) to shift the digit to the units place, then take modulo 10 to get that digit.
3fill in blank
hardFix the error in the counting array initialization for digits 0-9.
DSA Rust
let mut count = vec![0; [1]];
Attempts:
3 left
💡 Hint
Common Mistakes
Using 9 instead of 10, causing index errors.
Using 11 which wastes space.
✗ Incorrect
We need a count array of size 10 to count digits 0 through 9.
4fill in blank
hardFill both blanks to update the count array to hold cumulative counts.
DSA Rust
for i in 1..[1] { count[i] += count[[2]]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong loop range causing index out of bounds.
Adding count[i+1] instead of count[i-1].
✗ Incorrect
We loop from 1 to 10 (exclusive) and add the previous count to the current to get cumulative counts.
5fill in blank
hardFill all three blanks to place elements into output array in stable order.
DSA Rust
for &num in arr.iter().rev() { let digit = (num / [1]) % 10; output[count[digit] [2]] = num; count[digit] [3]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using += 1 instead of -= 1 causing wrong placement.
Not subtracting 1 from count[digit] index.
✗ Incorrect
We calculate the digit using place, place the number at count[digit] - 1 index, then decrement count[digit] by 1.
