Company: Visa_14feb
Difficulty: medium
Perfect Pairs A pair of integers (x, y) is called perfect when both of the following hold: min(|x - y|, |x + y|) <= min(|x|, |y|) max(|x - y|, |x + y|) >= max(|x|, |y|) You are given an array arr of n integers. Count the index pairs (i, j) with 0 <= i < j < n for which (arr[i], arr[j]) is a perfect pair. Both conditions use |v| , the absolute value of v , so the sign of an element never matters on its own — only its magnitude does. Input Format The first line contains a single integer n , the length of the array. The second line contains n space-separated integers arr[0], arr[1], ..., arr[n-1] . Output Format Print a single integer — the number of perfect index pairs. Constraints 2 <= n <= 2 * 10^5 -10^9 <= arr[i] <= 10^9 The answer can reach n (n - 1) / 2 , which is about 2 10^10 , so it does not fit in a 32-bit signed integer. Use long long in C++ and long in Java. Examples Example 1 Input: 4 -9 6 -2 1 Output: 2 Explanation: The perfect pairs are (-9, 6) an