Inversion count in an array

Given an array of integers A.
If i < j and A[i] > A[j] then the pair (i, j) is called an inversion of A.
Find the total number of inversions of A modulo (10^9 + 7).



Input Format

The only argument given is the integer array A.

Output Format

Return the number of inversions of A modulo (10^9 + 7).

Constraints

1 <= length of the array <= 100000
1 <= A[i] <= 10^9 

For Example

Input 1:
    A = [1, 2, 5, 4, 3]
Output 1:
    3

Input 2:
    A = [5, 17, 100, 11]
Output 2:
    1
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Inversion count in an array on Interview Code Editor
Sign Up
to access hints and editorial solutions for Inversion count in an array

Discussion


Loading...
Click here to start solving coding interview questions