Count inversions in a price series
Asked at DE Shaw, HRT
An inversion is a pair of positions i < j where prices[i] > prices[j], an earlier price that is higher than a later one. The inversion count measures how far a series is from sorted ascending. Count them.
prices = [3, 1, 2]
-> 2 # (3,1) and (3,2)
Return the number of inversions. Aim for .
Your answer
This one is open-ended. Work it through, then check your reasoning against the full solution.