Problem · Array

Find Number of Perfect Pairs

Learn this problem
MediumSalesforce logoSalesforceOA
See Salesforce hiring insights

Problem statement

Given an array, find the number of perfec pairs.

(x, y) is a perfect pair if satisfies:

  • min(|x-y|, |x+y|) <= min (|x|, |y|) and max(|x-y|, |x+y|) > max(|x|, |y|)
  • Function

    findNumberOfPerfectPairs(arr: int[]) → int

    Examples

    Example 1

    arr = [2, 5, -3]return = 2
    out of (2, 5) , (5, -3) and (2, -3), (2, -3) and (5, -3) satisfy both the conditions. Therefore, the output is 2.

    More Salesforce problems

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