Tap here to switch tabs
Problem
Submissions

Problem: Number of Perfect Pairs

med
30 min
Try to solve the Number of Perfect Pairs problem.

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 = $ nums[i] and $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

med
30 min
Try to solve the Number of Perfect Pairs problem.

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 = $ nums[i] and $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