Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to reduce the size of the array by one after deletion at the end.
DSA C
if (size > 0) { size [1] 1; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+=' instead of '-=' increases the size incorrectly.
Using '*=' or '/=' changes the size in unintended ways.
✗ Incorrect
We use '-=' to decrease the size by one after deleting the last element.
2fill in blank
mediumComplete the code to check if the array is empty before deletion.
DSA C
if ([1] > 0) { size -= 1; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking 'capacity' instead of 'size' can cause errors because capacity is total space, not current elements.
Using 'index' or 'length' without proper context may cause logic errors.
✗ Incorrect
We check if 'size' is greater than zero to ensure the array is not empty before deleting.
3fill in blank
hardFix the error in the code that deletes the last element from the array.
DSA C
if (size > 0) { array[size - 1] = 0; // Clear last element size [1] 1; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' assigns a fixed value instead of decreasing size.
Using '+=' increases size incorrectly.
Using '*=' multiplies size, which is wrong here.
✗ Incorrect
We must decrease 'size' by one using '-=' to reflect the deletion of the last element.
4fill in blank
hardFill both blanks to correctly delete the last element and update the size.
DSA C
if (size [1] 0) { array[size [2] 1] = 0; size -= 1; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or '<=' in the condition causes wrong checks for empty array.
Using 'size' instead of 'size - 1' to access last element causes out-of-bounds error.
✗ Incorrect
We check if size is greater than zero before deletion, and access the last element at index size - 1.
5fill in blank
hardFill all three blanks to delete the last element safely and update the array size.
DSA C
if (size [1] 0) { array[size [2] 1] = [3]; size -= 1; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '-' for index causes out-of-bounds access.
Setting last element to a non-zero value does not clear it properly.
Checking size with '<' or '<=' causes wrong behavior.
✗ Incorrect
We check if size is greater than zero, access last element at size - 1, and set it to 0 before decreasing size.
