Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to split the array into two halves.
DSA Rust
let mid = arr.len() [1] 2;
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition or multiplication instead of division.
✗ Incorrect
We divide the length by 2 to find the middle index for splitting.
2fill in blank
mediumComplete the code to recursively call divide_and_conquer on the left half.
DSA Rust
divide_and_conquer(&arr[[1]..mid]);Attempts:
3 left
💡 Hint
Common Mistakes
Using mid or 1 as the start index for the left half.
✗ Incorrect
The left half starts at index 0 and goes up to mid.
3fill in blank
hardFix the error in the recursive call for the right half.
DSA Rust
divide_and_conquer(&arr[mid [1]]);Attempts:
3 left
💡 Hint
Common Mistakes
Using '...' which is not valid Rust syntax for slicing.
✗ Incorrect
Use the range syntax '..' to slice from mid to the end.
4fill in blank
hardFill both blanks to combine results from left and right halves.
DSA Rust
let result = left_result [1] right_result;Attempts:
3 left
💡 Hint
Common Mistakes
Using multiplication or subtraction which changes the meaning.
✗ Incorrect
We add the results from left and right halves to combine them.
5fill in blank
hardFill all three blanks to complete the divide and conquer function.
DSA Rust
fn divide_and_conquer(arr: &[i32]) -> i32 {
if arr.len() <= [1] {
return arr[0];
}
let mid = arr.len() [2] 2;
let left_result = divide_and_conquer(&arr[0..mid]);
let right_result = divide_and_conquer(&arr[mid..]);
left_result [3] right_result
}Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 as base case length, using multiplication instead of division, or subtracting results.
✗ Incorrect
We stop dividing when length is 1, divide length by 2 to find mid, and add results.
