Out-of-Order Pairs
A pair of positions i < j in nums is out of order when nums[i] > nums[j]: the earlier item is strictly bigger than the later one. Return how many out-of-order pairs nums has.
A list in non-decreasing order has none, and a strictly decreasing list of n items has n * (n - 1) / 2. Equal items never form an out-of-order pair.
Example 1
nums [3,1,2]
returns 2
3 comes before 1 and before 2, and both are smaller: the pairs (0, 1) and (0, 2).
Example 2
nums [1,2,3]
returns 0
Nothing is out of order.
Constraints
0 <= len(nums) <= 100-1000 <= nums[i] <= 1000
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.