Created
September 4, 2016 21:08
-
-
Save mghamsar/af194f693c63a99cc80bef1e8d087c0a to your computer and use it in GitHub Desktop.
Sample codes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int countPairsWithDiffK(int arr[], int n, int k) | |
{ | |
int count = 0; | |
// Pick all elements one by one | |
for (int i = 0; i < n; i++) | |
{ | |
// See if there is a pair of this picked element | |
for (int j = i+1; j < n; j++) | |
if (arr[i] - arr[j] == k || arr[j] - arr[i] == k ) | |
count++; | |
} | |
return count; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment