Complete the code to initialize the inversion count variable.
int count = [1];We start counting inversions from zero because initially no pairs are counted.
Complete the code to compare elements for inversion detection.
if (arr[i] [1] arr[j])
An inversion is when a larger element appears before a smaller one, so we check if arr[i] > arr[j].
Fix the error in the nested loop condition to avoid out-of-range errors.
for (int j = i + 1; j [1] arr.Length; j++)
The loop should run while j is less than arr.Length to stay within array bounds.
Fill both blanks to correctly increment the inversion count inside the nested loops.
if (arr[i] [1] arr[j]) { count [2]; }
We check if arr[i] > arr[j] to find an inversion, then increment count by 1 using ++.
Fill all three blanks to complete the method that counts inversions in an array.
public static int CountInversions(int[] arr) {
int count = [1];
for (int i = 0; i [2] arr.Length - 1; i++) {
for (int j = i + 1; j [3] arr.Length; j++) {
if (arr[i] > arr[j]) {
count++;
}
}
}
return count;
}Initialize count to 0. Outer loop runs while i < arr.Length - 1. Inner loop runs while j < arr.Length.
