Problem · Array

Find Number of Perfect Pairs

Learn this problem
MediumLinkedIn logoLinkedInOA

Problem statement

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.

Function

findNumberOfPerfectPairs(nums: int[]) → int

Complete the function findNumberOfPerfectPairs in the editor.

findNumberOfPerfectPairs has the following parameter:

  1. int[] nums: an array of integers

Returns

int: the number of perfect pairs

Examples

Example 1

nums = [2, -3, 5]return = 2
(2, -3) and (-3, 5) are perfect pairs

More LinkedIn problems

drafts saved locally
public int findNumberOfPerfectPairs(int[] nums) {
  // write your code here
}
nums[2, -3, 5]
expected2
checking account