Tap here to switch tabs
Problem
Submissions

Problem: Number of Perfect Pairs

Number of Perfect Pairs counts index pairs in an integer array where the smaller absolute sum or difference is no greater than the smaller magnitude and the larger is no less than the larger magnitude.

Statement

You are given an integer array nums.

A pair of indices (i,j)(i, j) is considered a perfect pair if 0≤i<j<0 \leq i < j < nums.length and the following two conditions are satisfied for a=a = nums[i] and b=b = nums[j]:

  1. min⁡(∣a−b∣,∣a+b∣)≤min⁡(∣a∣,∣b∣)\min(|a - b|, |a + b|) \leq \min(|a|, |b|)

  2. max⁡(∣a−b∣,∣a+b∣)≥max⁡(∣a∣,∣b∣)\max(|a - b|, |a + b|) \geq \max(|a|, |b|)

Return the total number of perfect pairs in nums.

Constraints:

  • 2≤2 \leq nums.length ≤105\leq 10^5

  • −109≤-10^9 \leq nums[i] ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Number of Perfect Pairs

Number of Perfect Pairs counts index pairs in an integer array where the smaller absolute sum or difference is no greater than the smaller magnitude and the larger is no less than the larger magnitude.

Statement

You are given an integer array nums.

A pair of indices (i,j)(i, j) is considered a perfect pair if 0≤i<j<0 \leq i < j < nums.length and the following two conditions are satisfied for a=a = nums[i] and b=b = nums[j]:

  1. min⁡(∣a−b∣,∣a+b∣)≤min⁡(∣a∣,∣b∣)\min(|a - b|, |a + b|) \leq \min(|a|, |b|)

  2. max⁡(∣a−b∣,∣a+b∣)≥max⁡(∣a∣,∣b∣)\max(|a - b|, |a + b|) \geq \max(|a|, |b|)

Return the total number of perfect pairs in nums.

Constraints:

  • 2≤2 \leq nums.length ≤105\leq 10^5

  • −109≤-10^9 \leq nums[i] ≤109\leq 10^9