Complete the code to split the array into two halves.
int mid = [1] / 2;
The length of an array in Java is accessed using arr.length.
Complete the code to copy the left half of the array.
int[] left = Arrays.copyOfRange(arr, 0, [1]);
The left half goes from index 0 up to but not including mid, so mid is correct.
Fix the error in the merge function to correctly compare elements.
if (left[i] [1] right[j]) {
We pick the smaller element first, so we use < to compare.
Fill both blanks to copy remaining elements after merging.
while (i < [1]) { arr[k++] = left[[2]++]; }
We copy remaining elements from left array while i < left.length, and increment i as index.
Fill all three blanks to complete the merge function's main loop.
while (i < [1] && j < [2]) { if (left[i] [3] right[j]) { arr[k++] = left[i++]; } else { arr[k++] = right[j++]; } }
The loop runs while i < left.length and j < right.length. The comparison uses < to pick smaller element.
