Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to remove the last element from the array by decreasing the size.
DSA Java
if (size > 0) { size = size [1] 1; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '-' to change size.
Trying to multiply or divide size.
✗ Incorrect
To delete the last element, we reduce the size by 1 using the minus operator.
2fill in blank
mediumComplete the code to check if the array is empty before deletion.
DSA Java
if ([1] > 0) { size--; }
Attempts:
3 left
💡 Hint
Common Mistakes
Checking capacity or array length instead of size.
Using an undefined variable like index.
✗ Incorrect
We check if 'size' is greater than zero to ensure there is an element to delete.
3fill in blank
hardFix the error in the deletion method to correctly update the size.
DSA Java
public void deleteLast() {
if (size > 0) {
size [1] 1;
}
}Attempts:
3 left
💡 Hint
Common Mistakes
Using '+=' which increases size.
Using '*=' or '/=' which are incorrect here.
✗ Incorrect
The size should be decreased by 1 using the '-=' operator to delete the last element.
4fill in blank
hardFill both blanks to correctly check and delete the last element.
DSA Java
if ([1] > 0) { [2]--; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using capacity or index instead of size.
Decrementing the wrong variable.
✗ Incorrect
We check if size > 0 and then decrease size by 1 to delete the last element.
5fill in blank
hardFill all three blanks to implement a safe deleteLast method.
DSA Java
public void deleteLast() {
if ([1] > 0) {
[2] [3] 1;
}
}Attempts:
3 left
💡 Hint
Common Mistakes
Using '+=' instead of '-='.
Checking or updating wrong variables.
✗ Incorrect
Check if size > 0, then reduce size by 1 using '-=' operator on size.
