solve(nums) — an inversion is a pair of indices i < j withnums[i] > nums[j]. Return how many inversions nums has. A double loop is O(n²);
solve it in O(n log n) by counting while you merge sort.
When merging two sorted halves, every time a value from the right half is placed
before the values still waiting in the left half, it forms an inversion with each of
them: add the number of remaining left values.
Examples
solve([2,4,1,3,5]) → 3 // (2,1) (4,1) (4,3)
solve([1,2,3]) → 0
solve([5,4,3,2,1]) → 10Sample tests