Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to find the middle index of the array segment.
DSA C
int mid = (low + [1]) / 2;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using low twice instead of high.
Using mid variable before assignment.
✗ Incorrect
The middle index is calculated by adding low and high indices and dividing by 2.
2fill in blank
mediumComplete the code to return the maximum of two integers.
DSA C
int max = (a > [1]) ? a : b; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing a with itself.
Returning wrong variable.
✗ Incorrect
We compare a and b, returning the greater value.
3fill in blank
hardFix the error in the loop that finds maximum crossing subarray sum.
DSA C
for (int i = mid; i >= [1]; i--) { sum += arr[i]; if (sum > left_sum) left_sum = sum; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using high instead of low.
Loop direction incorrect.
✗ Incorrect
The loop should run from mid down to low index to cover left half.
4fill in blank
hardFill both blanks to correctly compute the maximum crossing subarray sum.
DSA C
int right_sum = INT_MIN; int sum = 0; for (int j = mid + 1; j <= [1]; j++) { sum += arr[j]; if (sum > [2]) right_sum = sum; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using left_sum instead of right_sum.
Comparing with wrong variable.
✗ Incorrect
The loop runs from mid+1 to high. We compare sum with right_sum to update it.
5fill in blank
hardFill all three blanks to return the maximum subarray sum among left, right, and crossing sums.
DSA C
return [1](left_sum, [2](right_sum, [3]));
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using sum instead of max.
Wrong order of arguments.
✗ Incorrect
We use max function twice to find the maximum among three sums.