Count Pairs With Difference

Medium · rating 1400 · Hashing, Arrays

The first line contains n and k. The second line has n integers. Print the number of index pairs (i, j) with i < j and |ai - aj| = k.

Constraints: 1 ≤ n ≤ 105, 0 ≤ k ≤ 109

Related problems

Open Count Pairs With Difference in Code Arena →