This is a solution to the Codility problem Inversion Count. An *inversion* is a tuple \((p,q)\) where \(p < q\) and \(A[p] > A[q]\) for a given array \(A\).

The idea is to use a modified mergesort that counts the number of inversion pairs. In Java:

This is a solution to the Codility problem Inversion Count. An *inversion* is a tuple \((p,q)\) where \(p < q\) and \(A[p] > A[q]\) for a given array \(A\).

The idea is to use a modified mergesort that counts the number of inversion pairs. In Java: