Finding the number of pairs in array with given difference
Given an array of N distinct values, how to find the number of pairs with a difference of K? For example, given an array [3, 1, 4, 2, 5] and K= 2, there are 3 pairs with a difference of 2. Namely {1,3}, {2,4}, {3,5}. One obvious solution could be to examine each possible pair…