Problem · Array

Find All Pairs of Integers

Learn this problem
MediumSalesforceFULLTIMEOA
See Salesforce hiring insights

Problem statement

Given array of integers, find all pairs of integers (x,y) from the array that satisfy below conditions:

  1. min(|x - y|, |x + y|) <= min(|x|, |y|)
  2. max(|x - y|, |x + y|) >= max(|x|, |y|)

Function

findAllPairs(arr: int[]) → int[][]

Examples

Example 1

arr = [2, 5, -3]return = [[2, -3], [5, -3]]
An educated guess - The pairs that satisfy the given conditions are:
  • (2, -3): min(|2 - (-3)|, |2 + (-3)|) = min(5, 1) = 1 <= min(2, 3) = 2 and max(5, 1) = 5 >= max(2, 3) = 3
  • (5, -3): min(|5 - (-3)|, |5 + (-3)|) = min(8, 2) = 2 <= min(5, 3) = 3 and max(8, 2) = 8 >= max(5, 3) = 5
  • Constraints

    🍅🍅

    More Salesforce problems

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