Perfect Pairs
A pair of integers (x, y) is perfect if both of the following conditions are met:
- min(|x - y|, |y - x|) ≤ min(|x|, |y|)
- max(|x - y|, |y - x|) > max(|x|, |y|)
Given an array arr of length n, find the number of perfect pairs
(arr[i], arr[j]) where 0 ≤ i < j < n.
Here min(a, b) is the minimum of a and b, max(a, b) is the maximum of a and b,
and |x| is the absolute value of x.
Function Description
Complete the function getPerfectPairsCount in the editor below.
getPerfectPairsCount has the following parameter:
int arr[n]: an array of integers
Returns
int: the number of perfect pairs
Constraints:
- 2 ≤ n ≤ 2*105
- -109 ≤ arr[i] ≤ 109
Example
Unlock to view complete problem details
and practice with sample input/output
Was this article helpful?
View Test Cases & Run Code requires membership
Input Variables
Execution Result:
