#K63437. Counting Inversions in an Array
Counting Inversions in an Array
Counting Inversions in an Array
Given an array of integers, you are required to count the number of inversions needed to sort the array in ascending order. An inversion is a pair of indices \( (i, j) \) such that \( i arr[j] \). In other words, the total number of inversions is given by the formula:
\( I = \sum_{i arr[j]\}} \)
For example, for the array [2, 3, 8, 6, 1], the inversion count is 5. Your task is to implement an efficient algorithm to compute this inversion count.
inputFormat
The first line contains an integer \( N \), representing the number of elements in the array. The second line contains \( N \) space-separated integers representing the array elements.
outputFormat
Output a single integer representing the number of inversions in the array.
## sample5
2 3 8 6 1
5
</p>