0
0
DSA Cprogramming~10 mins

Find Maximum Subarray Divide and Conquer in DSA C - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Amid
Bhigh
Clow
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using low twice instead of high.
Using mid variable before assignment.
2fill in blank
medium

Complete 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'
A0
Ba
Cmax
Db
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing a with itself.
Returning wrong variable.
3fill in blank
hard

Fix 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'
Alow
Bhigh
Cmid
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using high instead of low.
Loop direction incorrect.
4fill in blank
hard

Fill 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'
Ahigh
Bright_sum
Cleft_sum
Dsum
Attempts:
3 left
💡 Hint
Common Mistakes
Using left_sum instead of right_sum.
Comparing with wrong variable.
5fill in blank
hard

Fill 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'
Amax
Bleft_sum
Cright_sum
Dsum
Attempts:
3 left
💡 Hint
Common Mistakes
Using sum instead of max.
Wrong order of arguments.