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]) -> 0
  • countInversions([3, 2, 1]) -> 3
Compile and test (Ctrl+Enter)