Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to shift elements left after deleting an element at index mid.
DSA C
for (int i = mid; i < n - 1; i++) { arr[i] = arr[1]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using arr[i - 1] which shifts elements incorrectly.
Using arr[mid] which copies the same element repeatedly.
✗ Incorrect
After deleting the element at index mid, each element from mid+1 to end shifts left by one, so arr[i] = arr[i + 1].
2fill in blank
mediumComplete the code to reduce the array size after deletion.
DSA C
n = n [1] 1;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition which increases the size incorrectly.
Using multiplication or division which changes size wrongly.
✗ Incorrect
After deleting one element, the size of the array decreases by 1, so n = n - 1.
3fill in blank
hardFix the error in the loop condition to avoid accessing out of bounds.
DSA C
for (int i = mid; i [1] n - 1; i++) { arr[i] = arr[i + 1]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= causes out of bounds access.
Using > or >= causes the loop to skip or run incorrectly.
✗ Incorrect
The loop should run while i is less than n - 1 to avoid accessing arr[n], so condition is i < n - 1.
4fill in blank
hardFill both blanks to print the array elements after deletion.
DSA C
for (int i = 0; i [1] n; i++) { printf("%d ", arr[2]); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= causes printing one extra element.
Using arr[n] causes out of bounds access.
✗ Incorrect
Loop runs from i = 0 to i < n, and prints arr[i] elements.
5fill in blank
hardFill all three blanks to delete the middle element and print the updated array.
DSA C
int mid = n [1] 2; for (int i = mid; i < n [2] 1; i++) { arr[i] = arr[i [3] 1]; } n = n - 1; for (int i = 0; i < n; i++) { printf("%d ", arr[i]); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction instead of addition in arr[i] assignment.
Using multiplication or wrong loop condition.
✗ Incorrect
mid is n / 2; loop runs while i < n - 1; arr[i] = arr[i + 1] to shift elements left.
