Complete the code to find the middle index for splitting the array.
int mid = (left [1] right) / 2;
The middle index is found by adding left and right, then dividing by 2.
Complete the code to merge two sorted halves by comparing elements.
if (leftArr[i] [1] rightArr[j]) { merged[k++] = leftArr[i++]; } else { merged[k++] = rightArr[j++]; }
We pick the smaller element first, so we use < to compare.
Fix the error in the recursive call to sort the right half.
mergeSort(arr, [1], right);The right half starts from mid + 1 to right.
Fill both blanks to copy remaining elements from left and right arrays after merging.
while (i < n1) merged[k++] = leftArr[1]; while (j < n2) merged[k++] = rightArr[2];
We copy remaining elements by using i++ and j++ to move indices.
Fill all three blanks to copy merged array back to original array.
for (int idx = 0; idx < n1 + n2; idx++) arr[1] = merged[2]; [3]
We copy merged elements back starting at left index. The comment marks end of copying.
