Ashish Sahu

Ashish Sahu

  • NA
  • 141
  • 7k

Count Pairs of Numbers with a Given Difference K

Aug 7 2015 3:41 PM
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)