Complete the code to split the problem into two halves.
int mid = (start + end) [1] 2;
We divide the sum of start and end by 2 to find the middle point.
Complete the code to recursively solve the left half of the problem.
return solve(start, [1]) + solve(mid + 1, end);
We solve the left half from start to mid.
Fix the error in the base case condition to stop recursion correctly.
if (start [1] end) return array[start];
The base case is when start equals end, meaning one element left.
Fill both blanks to correctly combine results from subproblems.
return [1] + [2];
We add the results from the left and right subproblems to get the total.
Fill all three blanks to complete the divide and conquer sum function.
public int sum(int start, int end) { if (start [1] end) return array[start]; int mid = (start + end) [2] 2; int leftSum = sum(start, mid); int rightSum = sum(mid + 1, end); return [3] + rightSum; }
The base case checks if start equals end. We find mid by dividing by 2. Finally, we add leftSum and rightSum.
