Problem · Array
Find Number of Perfect Pairs
A perfect pair (x, y) is such that min( | x - y |, | x + y | ) <= min( | x |, | y |) and max( | x - y |, | x + y | ) >= max( | x |, | y |). Given an array of unsorted integers, find the number of perfect pairs.
Complete the function findNumberOfPerfectPairs in the editor.
findNumberOfPerfectPairs has the following parameter:
int[] nums: an array of integers
Returns
int: the number of perfect pairs
Examples
01 · Example 1
nums = [2, -3, 5] return = 2
(2, -3) and (-3, 5) are perfect pairs
More LinkedIn problems
public int findNumberOfPerfectPairs(int[] nums) {
// write your code here
}
nums[2, -3, 5]
expected2
sign in to submit