1
Answer

Count Pairs of Numbers with a Given Difference K

Ashish Sahu

Ashish Sahu

9y
649
1
Hi Experts,
 
Given an unsorted array and a number n, find if there exists a pair of elements in the array whose difference is n. Return count of such pairs.
Example k=4 and a[]={7,623,19,10,11,9,3,15}
Output should be : 6
Pairs can be:
7,11(11-7=4)
7,3(7-3=4)
6,10(10-6=4)
19,23(23-19=4)
15,19(19-15=4)
15,11(15-11=4)
 
Please Help me.
 
Thanks & Regards
Ashish Kumar Sahu 
Answers (1)