Given an integer array nums, return the number of reverse pairs in the array. A reverse pair is a pair (i, j) where 0 <= i < j < nums.length and nums[i] > 2 * nums[j].
Example 1
Input: nums = [1,3,2,3,1]
Output: 2
Explanation: A reverse pair needs nums[i] > 2 × nums[j] with i < j. Both 3s (indices 1 and 3) are more than twice the final 1 (index 4), giving 2 pairs. No other pair qualifies.
Example 2
Input: nums = [2,4,3,5,1]
Output: 3
Explanation: The final 1 (index 4) is less than half of 4, 3 and 5, giving the pairs (1,4), (2,4) and (3,4). No other pair qualifies, so the answer is 3.
Example 3
Input: nums = [1,2,3,4]
Output: 0
Explanation: The array is increasing, so no earlier number can be more than twice a later one.
During merge sort, before merging two sorted halves, count pairs where a left element is more than twice a right element. Sorted halves let a two-pointer sweep count these in linear time.
Run checks all cases above. Submit evaluates all test cases.