Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare an integer array of size 5.
DSA C++
int arr[[1]];Attempts:
3 left
💡 Hint
Common Mistakes
Using a size different from 5.
Forgetting to specify the size.
✗ Incorrect
The array size should be 5 to hold 5 elements.
2fill in blank
mediumComplete the code to find the middle index of the array.
DSA C++
int mid = [1] / 2;
Attempts:
3 left
💡 Hint
Common Mistakes
Using arr.size() which is invalid for raw arrays.
Using sizeof(arr) alone gives total bytes, not element count.
✗ Incorrect
To find the number of elements in a C++ array, divide total size by element size.
3fill in blank
hardFix the error in the loop to shift elements right from the middle index.
DSA C++
for (int i = 4; i >= [1]; i--) { arr[i + 1] = arr[i]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Starting loop from mid + 1 causes skipping the middle element.
Starting from 0 causes overwriting elements incorrectly.
✗ Incorrect
Start shifting from the middle index to make space for new element.
4fill in blank
hardFill both blanks to insert value 99 at middle index and print the array.
DSA C++
arr[[1]] = 99; for (int i = 0; i <= [2]; i++) { std::cout << arr[i] << " "; }
Attempts:
3 left
💡 Hint
Common Mistakes
Printing only up to 4 misses the new element.
Inserting at mid + 1 instead of mid places element wrongly.
✗ Incorrect
Insert at middle index and print up to the new last index (5).
5fill in blank
hardFill all three blanks to complete the insertion function for middle index.
DSA C++
void insertMiddle(int arr[], int n, int val) {
int mid = n [1] 2;
for (int i = n - 1; i >= [2]; i--) {
arr[i + 1] = arr[i];
}
arr[[3]] = val;
}Attempts:
3 left
💡 Hint
Common Mistakes
Using multiplication instead of division for mid.
Shifting from wrong index causing overwrite.
Inserting at wrong position.
✗ Incorrect
Calculate mid by dividing n by 2, shift from mid, insert at mid.
