Accenture OA-28 2024
Problem Description
Let j and k be two indices in an array A.
If j < k and A[j] > A[k], then the pair (j,k) is known as an "Inversion pair".
You are required to implement the following function:
int InversionCount(int *A, int n);
The function accepts an array 'A' of 'n' unique integers as its argument. You are required to calculate the number of 'Inversion pair' in an array A, and return.
Note:
If 'A' is NULL (None in case of python), return -1
If 'n' < 2, return 0
Input Format:
- The input consists of an array A of n integers.
Output Format:
Output the total number of inversion pairs in the array.
Constraints:
- 0 ≤ n ≤ 10^5
- -10^9 ≤ A[i] ≤ 10^9
Example
Sample Input:
[2, 3, 1, 5, 4]
Sample Output:
3
Explanation:
The inversion pairs are:
- (1, 2)
- (1, 3)
- (4, 5)