I have the list [5,2,10,9,7].
I want to count all the pairs that satisfy the condition ( i<j and list[i]>list[j] )
For example, the index of 5 is less than the index of 2 but 5 is greater than 2 so increase the counter by 1 and the same for (10,9) and (10,7)and (9,7) so the value of the counter will be 4
I have solved the problem but with complexity O(n^2), but I want to find a solution with the lowest time complexity.
This is the code that runs on O(n^2)
def ques(lista):
b=0
for i in range (len(lista)):
for j in range (1,len(lista)):
if i<j and lista[i]> lista[j] :
b+=1
return b