Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Number of Perfect Pairs

XPChallenge Points: 20
levelLevel: Medium

You are given an integer array nums.
A pair of indices (i, j) is called balanced perfect if the following conditions hold:
1. i < j
2. Let a = nums[i] and b = nums[j]. Then:
o min(|a - b|, |a + b|) <= min(|a|, |b|)
o max(|a - b|, |a + b|) >= max(|a|, |b|)
Your task is to count how many distinct balanced perfect pairs exist in the array.
Note:
The absolute value |x| refers to the non-negative value of x.

Example 1:

Input: nums = [-2, 4, -3, 6]

Output: 3

Example 2:

Input: nums = [1, 3, 5, 7]

Output: 5

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result