30:00
Given an integer array nums, return the number of reverse pairs in the array.
nums
A reverse pair is a pair (i, j) where:
(i, j)
0 <= i < j < nums.length
nums[i] > 2 * nums[j]
1≤nums.length≤5×1041 \leq \text{nums.length} \leq 5 \times 10^41≤nums.length≤5×104
−231≤nums[i]≤231−1-2^{31} \leq \text{nums}[i] \leq 2^{31} - 1−231≤nums[i]≤231−1
Run code to see results.
Merge sort the array. Before merging two sorted halves, count pairs with a left-half value greater than twice a right-half value.
0
1
2
3
4
total pairs
Given an integer array, count the index pairs i < j where nums[i] is greater than twice nums[j].