PAIRS1  Count the Pairs
Given N integers [0<N<=10^5], count the total pairs of integers that have a difference of K. (Everything can be done with 32 bit integers).
Input Format
1st line contains N & K (integers).
2nd line contains N numbers of the set. All the N numbers are distinct.
Output Format
One integer  the number of pairs of numbers that have a diff K.
Sample Input :
5 2
1 5 3 4 2
Sample Output :
3
Sample Input :
10 1
363374326 364147530 61825163 1073065718 1281246024 1399469912 428047635 491595254 879792181 1069262793
Sample Output :
0
hide comments
dewasemadi:
20210113 01:20:09
AC in a go..!


it_uchi:
20210109 21:22:01
AC in a GO.


pavit_1809:
20200420 18:40:49
Merge sort can also be applied as we are only supposed to check every pair and merge sort would do that in O(nlogn) time complexity.


ajaygupta007:
20200409 21:30:42
solved using both techinques


scolar_fuad:
20191127 18:22:58
just fix a number then find upper bound and lowerbound for every number+k


selisahil:
20190925 16:22:20
use hashing.... 

jinks:
20190917 08:05:24
why is sorting +binary search give runtime error? 

lx_lovin:
20190809 05:03:11
without sorting and binary search just do mapping


kushagra_2:
20190122 17:17:43
Sort + binary search O(nlogn) AC in one go!! 

atharvat77:
20190104 17:01:31
Good Question To Apply Binary Search

Added by:  psn 
Date:  20131018 
Time limit:  0.5s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: ASM64 
Resource:  Own 