Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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
✗ Incorrect
The first element of the prefix sum array should be the first element of the original array.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction instead of addition
Using multiplication or division which are incorrect here
✗ Incorrect
Each prefix sum element is the sum of the previous prefix sum and the current array element.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>=' or '>' which causes no iterations or wrong iterations
Using '<=' which causes out-of-bounds access
✗ Incorrect
The loop should run while i is less than n to avoid going out of array bounds.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in loop parts causing errors
Using uncommon variable names that confuse the logic
✗ Incorrect
The loop variable should be consistent; 'i' is commonly used for indexing.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same variable for both loops causing logic errors
Using inconsistent variable names inside loops
✗ Incorrect
Use 'i' for the prefix sum loop and 'j' for the print loop to avoid confusion.
