Counting Pairs
Given an integer k and a list of integers, count the number of distinct valid pairs of integers (a, b) in the list for which a + k = b. Two pairs of integers (a, b) and (c, d) are considered distinct if at least one element of (a, b) does not also belong to (c, d). Note that the elements in a pair might be the same element in the array. An instance of this is below where k = 0.
Complete the function countPairs in the editor.
countPairs has the following parameter(s):
int numbers[n]: array of integersint k: target difference
Returns
int: number of valid (a, b) pairs in the numbers array that have a difference of k
๐ 1001 thanks to spike for carring! ๐
1Example 1
2Example 2
Constraints
Limits and guarantees your solution can rely on.
2 <= n <= 2 * 10^50 <= numbers[i] <= 10^9, where 0 <= i < n0 <= k <= 10^9