Bird
0
0
DSA Cprogramming~10 mins

Prefix Sum Array 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 initialize the prefix sum array's first element.

DSA C
prefix_sum[0] = [1];
Drag options to blanks, or click blank then click option'
A-1
Barr[0]
Carr[1]
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Setting prefix_sum[0] to 0 instead of arr[0]
Using arr[1] which is the second element
Initializing with -1 which is incorrect
2fill in blank
medium

Complete the code to compute the prefix sum at index i inside the loop.

DSA C
prefix_sum[i] = prefix_sum[i - 1] [1] arr[i];
Drag options to blanks, or click blank then click option'
A+
B-
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction instead of addition
Using multiplication or division which are incorrect here
3fill in blank
hard

Fix the error in the loop condition to correctly iterate over the array elements.

DSA C
for (int i = 1; i [1] n; i++) {
Drag options to blanks, or click blank then click option'
A>
B<=
C>=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>=' or '>' which causes no iterations or wrong iterations
Using '<=' which causes out-of-bounds access
4fill in blank
hard

Fill both blanks to compute the prefix sum array using a for loop.

DSA C
for (int [1] = 1; [2] < n; [1]++) {
    prefix_sum[[1]] = prefix_sum[[1] - 1] + arr[[1]];
}
Drag options to blanks, or click blank then click option'
Ai
Bj
Ck
Dx
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in loop parts causing errors
Using uncommon variable names that confuse the logic
5fill in blank
hard

Fill all three blanks to create a prefix sum array and print its elements.

DSA C
int prefix_sum[n];
prefix_sum[0] = arr[0];
for (int [1] = 1; [2] < n; [1]++) {
    prefix_sum[[1]] = prefix_sum[[1] - 1] + arr[[1]];
}
for (int [3] = 0; [3] < n; [3]++) {
    printf("%d ", prefix_sum[[3]]);
}
Drag options to blanks, or click blank then click option'
Ai
Bj
Ck
Dx
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same variable for both loops causing logic errors
Using inconsistent variable names inside loops