Hackerrank - Search - Pairs
Given N integers, count the number of pairs of integers whose difference is k.
Sample Input
5 2
1 5 3 4 2
Sample Output
3
Explanation
There are 3 pairs of integers in the set with a difference of 2.
Sample Input
5 2
1 5 3 4 2
Sample Output
3
Explanation
There are 3 pairs of integers in the set with a difference of 2.
SolutionN, k = map(int, raw_input().split()) a = map(int,raw_input().split()) print len(set(a) & set(x + k for x in a))
Comments
Post a Comment