Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to insert an element at the end of the array.
DSA C++
arr[size] = [1];
size++;Attempts:
3 left
💡 Hint
Common Mistakes
Using 'index' instead of the new element value.
Using 'size' as the value instead of the element to insert.
✗ Incorrect
We assign the new element 'value' to the position at 'size', which is the current end of the array.
2fill in blank
mediumComplete the code to increase the size after insertion.
DSA C++
arr[size] = value;
[1];Attempts:
3 left
💡 Hint
Common Mistakes
Decreasing size instead of increasing.
Assigning size to zero after insertion.
✗ Incorrect
After inserting the element, we increase 'size' by 1 to reflect the new array length.
3fill in blank
hardFix the error in the insertion code to avoid overwriting existing elements.
DSA C++
if (size < capacity) { arr[[1]] = value; size++; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'size + 1' causes skipping and overwriting.
Using 'capacity' as index causes out-of-bounds error.
✗ Incorrect
We insert the new element at index 'size', which is the first free position, ensuring no overwriting.
4fill in blank
hardFill both blanks to check capacity and insert the element correctly.
DSA C++
if ([1] < [2]) { arr[size] = value; size++; }
Attempts:
3 left
💡 Hint
Common Mistakes
Checking 'value' instead of 'size' for capacity.
Using 'index' instead of 'capacity' for max size.
✗ Incorrect
We check if 'size' is less than 'capacity' before inserting to avoid overflow.
5fill in blank
hardFill all three blanks to insert an element and update size safely.
DSA C++
if ([1] < [2]) { arr[[3]] = value; size++; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'value' instead of 'size' or 'capacity' in conditions.
Inserting at wrong index causing overwrite.
✗ Incorrect
We check if 'size' is less than 'capacity', then insert at 'size' index and increment size.
