PythiloHard · 40 min · Task 100 of 100 · progress kept in this browser

Count inversions with merge sort

Return the number of index pairs with i less than j and items[i] greater than items[j], leaving input unchanged. Equal values are not inversions. Use O(n log n) time.

left = [2, 4, 7]
right_value, consumed = 1, 0
print(len(left)-consumed)  # new inversions
Your task

Return the number of index pairs with i less than j and items[i] greater than items[j], leaving input unchanged. Equal values are not inversions. Use O(n log n) time.

All lessons