You are given a list that consists of the numbers . A pair of indices is an inversion if and the element at index on the list is greater than the element at index .
You may assume that is at most .
In a file inversions.py
, implement a function count
that returns the total number of inversions in the list.
def count(t): # TODO if __name__ == "__main__": print(count([1,3,2])) # 1 print(count([1])) # 0 print(count([4,3,2,1])) # 6 print(count([1,8,2,7,3,6,4,5])) # 12
Explanation: The list contains the inversions , , , , and .