Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to find the middle index of the array segment.
DSA Java
int mid = (low [1] high) / 2;
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction instead of addition.
Using multiplication which is incorrect here.
✗ Incorrect
The middle index is found by adding low and high and dividing by 2.
2fill in blank
mediumComplete the code to find the maximum of three integers.
DSA Java
return Math.max(leftMax, Math.max(rightMax, [1]));
Attempts:
3 left
💡 Hint
Common Mistakes
Using variables that do not exist.
Confusing leftMax and rightMax with crossMax.
✗ Incorrect
The crossMax variable holds the maximum sum crossing the middle.
3fill in blank
hardFix the error in the loop that calculates max crossing sum on the left side.
DSA Java
for (int i = mid; i >= [1]; i--) {
Attempts:
3 left
💡 Hint
Common Mistakes
Using mid as the lower bound causes an empty loop.
Using high causes index out of range.
✗ Incorrect
The loop must go down to the low index to cover the left half.
4fill in blank
hardFill both blanks to correctly calculate the max crossing sum on the right side.
DSA Java
int sum = 0; int rightSum = Integer.MIN_VALUE; for (int j = mid + 1; j [1] high; j[2]) { sum += arr[j]; if (sum > rightSum) rightSum = sum; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using < excludes the last element.
Using -- decrements j causing infinite loop.
✗ Incorrect
The loop runs from mid+1 up to high inclusive, incrementing j each time.
5fill in blank
hardFill all three blanks to complete the recursive max subarray function call and return statement.
DSA Java
int leftMax = findMaxSubarray(arr, low, [1]); int rightMax = findMaxSubarray(arr, [2], high); int crossMax = maxCrossingSum(arr, low, mid, high); return [3](leftMax, Math.max(rightMax, crossMax));
Attempts:
3 left
💡 Hint
Common Mistakes
Using Math.min instead of Math.max.
Incorrect indices causing stack overflow.
✗ Incorrect
The left half ends at mid, right half starts at mid+1, and return the max of three sums.
