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.


Solution
N, k = map(int, raw_input().split())
a = map(int,raw_input().split())

print len(set(a) & set(x + k for x in a))

Comments

Best Programming language for machine learning.

Popular posts from this blog

Hackerrank - Dynamic Programming - The Coin Change Problem

Hackerrank - Implementation - Picking Numbers