FastPrepEqual Difference Pairs
Problem · Hash Table

Equal Difference Pairs

Learn this problem
MediumSISusquehanna International GroupINTERNOA

Problem statement

See the Image Source section at the bottom of this page for the original problem descritpion and example explanation :)

Imagine two friends, Alice and Bob, who both have lists of numbers. They want to play a game to see how many special pairs they can find. Each pair consists of two numbers, one from Alice's list and one from Bob's list. But there's a twist: they are only interested in pairs where a certain condition is met.

Function

sigDiffPairs(a: int[], b: int[]) → int

Examples

Example 1

a = [2, -2, 5, 3]b = [1, 5, -1, 1]return = 6
For (i, j) = (0, 0) equality holds: a[0] - b[0] = 2 - 1 = 1 and a[0] - b[0] = 2 - 1 = 1 For (i, j) = (0, 1) equality holds: a[0] - b[1] = 2 - 5 = -3 and a[1] - b[0] = -2 - 1 = -3 For (i, j) = (0, 2) equality doesn't hold: a[0] - b[2] = 2 - (-1) = 3 and a[2] - b[0] = 5 - 1 = 4 For (i, j) = (0, 3) equality doesn't hold: a[0] - b[3] = 2 - 1 = 1 and a[3] - b[0] = 3 - 1 = 2 For (i, j) = (1, 1) equality holds: a[1] - b[1] = (-2) - 5 = -7 and a[1] - b[1] = -2 - 5 = -7 For (i, j) = (1, 2) equality does not holds: a[1] - b[2] = (-2) - (-1) = -1 and a[2] - b[1] = 5 - 5 = 0 For (i, j) = (1, 3) equality does not holds: a[1] - b[3] = (-2) - 1 = -3 and a[3] - b[1] = 3 - 5 = -2 For (i, j) = (2, 2) equality holds: a[2] - b[2] = 5 - (-1) = 6 and a[2] - b[2] = 5 - (-1) = 6 For (i, j) = (2, 3) equality holds: a[2] - b[3] = 5 - 1 = 4 and a[3] - b[2] = 3 - (-1) = 4 For (i, j) = (3, 3) equality holds: a[3] - b[3] = 3 - 1 = 2 and a[3] - b[3] = 3 - 1 = 2

Example 2

a = [25, 0]b = [0, 25]return = 3
n/a

Constraints

🍓🍓

More Susquehanna International Group problems

drafts saved locally
public int sigDiffPairs(int[] a, int[] b) {
  // write your code here
}
a[2, -2, 5, 3]
b[1, 5, -1, 1]
expected6
checking account