Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to insert an element at the end of the array.
DSA Java
int[] arr = new int[5]; int size = 0; int element = 10; arr[size[1]0] = element; size++;
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' instead of '+' causes wrong index access.
Using '*' or '/' causes syntax or logic errors.
✗ Incorrect
We use '+' to add the index offset. Here, size + 0 means the first empty position.
2fill in blank
mediumComplete the code to increase the size after insertion.
DSA Java
int[] arr = new int[5]; int size = 0; arr[size] = 20; size[1];
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-=' decreases size incorrectly.
Using '*=' or '/=' does not change size as intended.
✗ Incorrect
We increase size by 1 after inserting an element to track the new end.
3fill in blank
hardFix the error in the insertion code to avoid ArrayIndexOutOfBoundsException.
DSA Java
int[] arr = new int[3]; int size = 3; int element = 5; if (size < arr.length) { arr[size[1]0] = element; size++; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' causes negative index error.
Using '*' or '/' causes syntax errors.
✗ Incorrect
Use '+' to insert at the current size index, which is the next free position.
4fill in blank
hardFill both blanks to complete the insertion and size update correctly.
DSA Java
int[] arr = new int[4]; int size = 2; int element = 15; if (size [1] arr.length) { arr[size[2]0] = element; size++; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' causes wrong condition logic.
Using '-' causes wrong index calculation.
✗ Incorrect
We check if size is less than array length and insert at size + 0 index.
5fill in blank
hardFill all three blanks to insert element and update size safely.
DSA Java
int[] arr = new int[5]; int size = 4; int element = 25; if (size [1] arr.length) { arr[size[2]0] = element; size[3]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' in condition causes logic error.
Using '-' for index causes wrong position.
Forgetting to increase size after insertion.
✗ Incorrect
Check size < length, insert at size + 0, then increase size by 1.
