Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to remove the element at the middle index from the array.
DSA C#
int[] arr = {1, 2, 3, 4, 5};
int mid = arr.Length / 2;
int[] result = new int[arr.Length - 1];
for (int i = 0, j = 0; i < arr.Length; i++) {
if (i == [1]) continue;
result[j++] = arr[i];
}Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong index to skip, like 0 or arr.Length.
Not skipping any index, causing no deletion.
✗ Incorrect
The middle index is stored in 'mid', so we skip copying the element at index 'mid' to delete it.
2fill in blank
mediumComplete the code to print all elements of the array after deletion.
DSA C#
foreach (int num in [1]) { Console.Write(num + " "); }
Attempts:
3 left
💡 Hint
Common Mistakes
Printing the original array instead of the updated one.
Using null or empty arrays causing no output.
✗ Incorrect
After deletion, the new array 'result' holds the updated elements to print.
3fill in blank
hardFix the error in the loop condition to avoid out-of-range errors.
DSA C#
for (int i = 0; i < [1]; i++) { Console.Write(result[i] + " "); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using the original array length causing index out of range.
Using incorrect length values causing runtime errors.
✗ Incorrect
The loop should run up to the length of 'result', the new array after deletion.
4fill in blank
hardFill both blanks to correctly shift elements after deletion.
DSA C#
for (int i = [1]; i < arr.Length - 1; i++) { arr[i] = arr[[2]]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Starting from wrong index causing incorrect shifts.
Using wrong index for assignment causing data loss.
✗ Incorrect
Start shifting from the middle index, assigning each element the next element's value.
5fill in blank
hardFill all three blanks to create a new array after shifting elements.
DSA C#
int[] newArr = new int[arr.Length - 1]; for (int i = 0; i < [1]; i++) { newArr[i] = arr[i]; } for (int i = [2]; i < newArr.Length; i++) { newArr[i] = arr[[3]]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Incorrect loop ranges causing index errors.
Wrong source index causing wrong elements copied.
✗ Incorrect
Copy elements before middle index, then copy elements after middle index shifted by one.
