Ixigo Dominating Pairs Count
At Ixigo, we often deal with ranking and comparing various entities like flights, hotels, or user preferences. Sometimes, a significant disparity in value between two items indicates a 'dominance' of one over the other. This problem models such a scenario where we need to count pairs exhibiting a strong form of dominance within a given sequence of values.
Your task is to implement a function countDominatingPairs that identifies and counts specific pairs within an array of integers. A pair (i, j) is considered "dominating" if it satisfies two conditions:
i must be strictly less than the index j (i < j).i must be strictly greater than twice the value at index j (nums[i] > 2 * nums[j]).Implement the countDominatingPairs function to return the total number of such dominating pairs found in the input array nums.
nums — An array of integers.(i, j) where i < j and nums[i] > 2 * nums[j].nums can contain positive, negative, or zero values.i and j is crucial: i must always precede j.nums[j] is very large, especially when multiplied by 2. In JavaScript/TypeScript, number type handles values up to 2^53 - 1 without precision loss for integers, which is sufficient for the given constraints.Examples
Example 1
Input:
nums = [2, 4, 3, 5, 1]
Output:
3
Note:
The dominating pairs are:
Example 2
Input:
nums = [1, 3, 2, 3, 1]
Output:
2
Note:
The dominating pairs are:
Example 3
Input:
nums = [5, 4, 3, 2, 1]
Output:
4
Note:
The dominating pairs are:
Constraints
1 <= nums.length <= 10^5-2 * 10^9 <= nums[i] <= 2 * 10^9number in JavaScript/TypeScript, long in Java/C++).Loading editor...