Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to insert a new element at the end of the array.
DSA C
arr[size] = [1];
size++; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using size as the value instead of the new element.
Assigning to arr[size-1] which overwrites the last element.
✗ Incorrect
We assign the new element to the position at the current size index, then increase size.
2fill in blank
mediumComplete the code to check if the array has space before insertion.
DSA C
if (size < [1]) { arr[size] = new_element; size++; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing size with arr instead of max_size.
Using new_element in the condition.
✗ Incorrect
We compare size with max_size to ensure there is space to insert.
3fill in blank
hardFix the error in the insertion code to avoid overwriting elements.
DSA C
arr[[1]] = new_element;
size++; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using size - 1 which overwrites the last element.
Using max_size which is out of bounds.
✗ Incorrect
Inserting at index size appends the element; size - 1 overwrites last element.
4fill in blank
hardFill both blanks to insert an element only if there is space.
DSA C
if ([1] < [2]) { arr[size] = new_element; size++; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping size and max_size in the condition.
Using new_element or arr in the condition.
✗ Incorrect
We check if size is less than max_size before inserting.
5fill in blank
hardFill all three blanks to insert and print the updated array size.
DSA C
if ([1] < [2]) { arr[[3]] = new_element; size++; printf("Size: %d\n", size); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using new_element as index.
Printing size before incrementing.
✗ Incorrect
Check size < max_size, insert at arr[size], then increment size.
