Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to reduce the array size by one after deletion at the end.
DSA C++
int size = 5; int arr[5] = {1, 2, 3, 4, 5}; // Delete last element size [1];
Attempts:
3 left
💡 Hint
Common Mistakes
Using ++ increases size instead of decreasing.
Using += or -= without a value is incorrect.
✗ Incorrect
Decreasing the size by one removes the last element logically.
2fill in blank
mediumComplete the code to print the last element before deletion.
DSA C++
int size = 4; int arr[5] = {10, 20, 30, 40, 50}; std::cout << arr[1] << std::endl;
Attempts:
3 left
💡 Hint
Common Mistakes
Using size as index causes out-of-bounds error.
Using 0 prints the first element, not last.
✗ Incorrect
Array indices start at 0, so last element is at size - 1.
3fill in blank
hardFix the error in the code to delete the last element safely.
DSA C++
int size = 3; int arr[5] = {5, 10, 15, 20, 25}; if (size > 0) { size [1]; } std::cout << "New size: " << size << std::endl;
Attempts:
3 left
💡 Hint
Common Mistakes
Incrementing size increases array size incorrectly.
Subtracting 2 may remove more elements than intended.
✗ Incorrect
Decrementing size by one safely deletes last element if size is positive.
4fill in blank
hardFill both blanks to print all elements after deleting the last one.
DSA C++
int size = 4; int arr[5] = {2, 4, 6, 8, 10}; size [1]; for (int i = 0; i [2] size; i++) { std::cout << arr[i] << " "; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= in loop prints one extra element.
Not decrementing size prints all elements including deleted.
✗ Incorrect
Decrement size to remove last element, then loop while i < size to print remaining.
5fill in blank
hardFill all three blanks to delete last element and print updated array size and elements.
DSA C++
int size = 3; int arr[5] = {7, 14, 21, 28, 35}; if (size [1] 0) { size [2]; } std::cout << "Size: " << size << std::endl; for (int i = 0; i [3] size; i++) { std::cout << arr[i] << " "; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using >= in condition allows deletion when size is zero.
Looping with <= prints extra element.
Not decrementing size keeps old size.
✗ Incorrect
Check size > 0 before decrementing size, then loop while i < size to print elements.
