Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to find the middle index for splitting the array.
DSA C++
int mid = (left [1] right) / 2;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction instead of addition.
Using multiplication which is incorrect here.
✗ Incorrect
The middle index is found by adding left and right, then dividing by 2.
2fill in blank
mediumComplete the code to merge two sorted halves by comparing elements.
DSA C++
if (leftArr[i] [1] rightArr[j]) { merged[k++] = leftArr[i++]; } else { merged[k++] = rightArr[j++]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using > instead of < causes wrong order.
Using <= or >= can cause duplicates or errors.
✗ Incorrect
We pick the smaller element first, so we use < to compare.
3fill in blank
hardFix the error in the recursive call to sort the right half.
DSA C++
mergeSort(arr, [1], right); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using mid instead of mid + 1 causes overlap.
Using right - 1 misses the last element.
✗ Incorrect
The right half starts from mid + 1 to right.
4fill in blank
hardFill both blanks to copy remaining elements from left and right arrays after merging.
DSA C++
while (i < n1) merged[k++] = leftArr[1]; while (j < n2) merged[k++] = rightArr[2];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using [k++] causes wrong indexing.
Not incrementing i or j causes infinite loops.
✗ Incorrect
We copy remaining elements by using i++ and j++ to move indices.
5fill in blank
hardFill all three blanks to copy merged array back to original array.
DSA C++
for (int idx = 0; idx < n1 + n2; idx++) arr[1] = merged[2]; [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using arr[idx] overwrites wrong part of array.
Missing the comment line is okay but less clear.
✗ Incorrect
We copy merged elements back starting at left index. The comment marks end of copying.