You will be given an array of integers and a target value. Determine the number of pairs of array elements that have a difference equal to a target value. code example
Example: two elements with difference K in c++
bool diffK(int A[], int N, int K) {
sort(A, A+N);
int i = 0, j = 0;
while (i < N && j < N) {
if (A[i] == A[j] + K) return true;
else if (A[i] < A[j] + K) i++;
else j++;
}
return false;
}