An array of k numbers is given. Determine the number of inversions in the array (i.e., such pairs of elements in which the larger number is to the left of the less-th).

    1 answer 1

    You set a counter variable, reset it. Next cycle look through the array (i varies from 0 to k-2), compare the variables i and i + 1. If array [i]> array [i + 1], increase the counter by 1.