Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to insert a value at the middle index of the array.
DSA Java
int middle = arr.length / [1];Attempts:
3 left
💡 Hint
Common Mistakes
Using 3 or 4 instead of 2 for division.
Using floating point division instead of integer division.
✗ Incorrect
To find the middle index, divide the array length by 2.
2fill in blank
mediumComplete the code to shift elements right to make space for the new element.
DSA Java
for (int i = arr.length - 1; i > [1]; i--) { arr[i] = arr[i - 1]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Starting shift from middle + 1 instead of middle.
Using middle - 1 which misses the middle element.
✗ Incorrect
We shift elements starting from the last index down to the middle index to make space.
3fill in blank
hardFix the error in the insertion statement.
DSA Java
arr[[1]] = newValue;Attempts:
3 left
💡 Hint
Common Mistakes
Inserting at middle + 1 which skips the middle position.
Using arr.length which is out of bounds.
✗ Incorrect
The new value should be inserted exactly at the middle index.
4fill in blank
hardFill both blanks to complete the code that inserts a value at the middle index.
DSA Java
int middle = arr.length / [1]; for (int i = arr.length - 1; i > [2]; i--) { arr[i] = arr[i - 1]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 3 instead of 2 for division.
Shifting elements starting from middle + 1 instead of middle.
✗ Incorrect
Divide length by 2 to find middle, then shift elements starting from the last index down to middle.
5fill in blank
hardFill all three blanks to complete the insertion code with middle calculation, shifting, and insertion.
DSA Java
int middle = arr.length / [1]; for (int i = arr.length - 1; i > [2]; i--) { arr[i] = arr[i - 1]; } arr[[3]] = newValue;
Attempts:
3 left
💡 Hint
Common Mistakes
Using 3 instead of 2 for division.
Inserting at wrong index like middle + 1.
✗ Incorrect
Calculate middle by dividing length by 2, shift elements from last to middle, then insert newValue at middle.
