We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
A quite simple Python approach that times out in 3 test cases:
frombisectimportbisect_right,insort# Complete the countInversions function below.defcountInversions(arr):inversions=len(arr)*(len(arr)-1)//2left=[]foridx,vinenumerate(arr):v_idx=bisect_right(left,v)inversions-=v_idxinsort(left,v)returninversions
Merge Sort: Counting Inversions
You are viewing a single comment's thread. Return to all comments →
A quite simple Python approach that times out in 3 test cases: