This page shows a solution to the problem ArrayInversionCount presented by Codility in the lesson 99 “ Future Training”.
from bisect import bisect
def solution(A):
N = len(A)
array = []
total = N*(N-1)//2
for e in A:
pos = bisect(array, e)
total -= pos
array.insert(pos, e)
return total if total <= 1000000000 else -1