← previousnext →
Problem
Return the number of pairs (i, j) with i < j and arr[i] > arr[j] (measures how far from sorted).
Examples
countInversions([1, 2, 3]) -> 0countInversions([3, 2, 1]) -> 3
Return the number of pairs (i, j) with i < j and arr[i] > arr[j] (measures how far from sorted).
countInversions([1, 2, 3]) -> 0countInversions([3, 2, 1]) -> 3