HACKRNDM  Hacking the random number generator
You recently wrote a random number generator code for a web application and now you notice that some cracker has cracked it. It now gives numbers at a difference of some given value k more predominantly. You being a hacker decide to write a code that will take in n numbers as input and a value k and find the total number of pairs of numbers whose absolute difference is equal to k, in order to assist you in your random number generator testing.
NOTE: All values fit in the range of a signed integer, n, k>=1
Input
1st line contains n & k.
2nd line contains n numbers of the set. All the n numbers are assured to be distinct.
(Edited: n <= 10^5)
Output
One integer saying the no of pairs of numbers that have a diff k.
Example
Input: 5 2
1 5 3 4 2 Output: 3
hide comments
rangey_18o3_20:
20210715 17:40:56
Think about the number of pairs for n=10^5. 

mkrishnasai:
20210621 17:27:54
In Java don't use 'BufferedReader' because the input format is not as mentioned, so it's resulting in Runtime error (NZEC) try 'Scanner' instead it executes within the given time limit. 

satyam_656:
20210605 15:23:07
smiply use map 

muzairs:
20210321 13:32:35
https://www.spoj.com/submit/HACKRNDM/id=27584170


makhan_28:
20210318 14:16:01
Solved it with 2pointer!! :) 

muzairs:
20210304 08:26:46
can ysomeone spot whats wrong with my code


majid:
20210213 10:46:50
Input described in Problem is wrong. Input takes values in "n" separate lines. 

asifalim:
20201130 19:09:21
accept in 1st attempt using trial and error algo 

kartik170901:
20200708 00:50:33
it is 2 pointer for O(n) why would one use binary search O(nlogn) Last edit: 20200708 00:50:47 

kumar_anubhav:
20200620 09:38:45
AC in one go !! binary search is faster than hashmap :)) 
Added by:  vijay 
Date:  20111015 
Time limit:  1s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: ASM64 
Resource:  Own Problem 