You are given an integer array nums. A reverse pair happens when an element on the left side is more than double an element on the right side.
Formally, for indices i < j, the pair (i, j) is a reverse pair if:
Your task is to count how many such valid reverse pairs exist in the array.
Input: nums = [4, 1, 8, 2]
Output: 2
Explanation:
Pairs: (0, 1) → 4 > 2 * 1 (2, 3) → 8 > 2 * 2 Total reverse pairs = 2
Input: nums = [10, 5, 2, 1]
Output: 6
Explanation:
All pairs (i, j) where i < j satisfy nums[i] > 2 * nums[j]: (0,1), (0,2), (0,3), (1,2), (1,3), (2,3) Total = 6
Accepted:
Submission: