Update appNew update is available. Click here to update.

Ninja And The Dance Competetion

Last Updated: 22 Feb, 2021
Difficulty: Easy


Try Problem

Ninja has been asked to organize a dance competition. Ninja decided that he will take individual entries and then will divide them into pairs. As part of the entry, he asked the participants to choose any number.

Ninja then thought of a creative method to divide them into pairs. He decided that he would select a number ‘K’, and then select numbers from the list that have a difference equal to ‘K’.

You need to help Ninja in finding the number of distinct pairs from the numbers with differences equal to ‘K’.

Let us suppose the numbers are chosen by participants: [2, 6, 5, 2, 3] and K = 3, then the distinct pairs having differences equal to K are: [2, 5] and [3, 6] so print 2. 
The list of numbers can contain duplicate numbers, you need to print only the distinct pairs.

For example [2, 2, 3, 4] and K = 1, so you need to print 2 as the two distinct pairs are: (2, 3) and (3, 4).
Input Format:
The first line contains a single integer ‘T’ representing the number of test cases. 

The first line of each test case will contain two space-separated integers ‘N’ and ‘K’, where ‘N’ denotes the number of elements of the array that contains the chosen numbers, and ‘K’ denotes the difference required between the pair elements.

The second line of each test case will contain ‘N’ space-separated integers denoting the chosen numbers by the participants.
Output Format:
For each test case, print a single integer that denotes the distinct pairs having differences equal to K. 

Output for every test case will be printed in a separate line.
1 <= T <= 10^2
0 <= N <= 10^4
0 <= K <= 10^4
0 <= ARR[i] <= 10^9

Where ‘ARR[i]’ is the value of elements of the array.

Time Limit: 1 sec