Skip to content

Instantly share code, notes, and snippets.

@mghamsar
Last active September 4, 2016 21:16
Show Gist options
  • Save mghamsar/90dbe50a65c532fc69dc55580ee7949f to your computer and use it in GitHub Desktop.
Save mghamsar/90dbe50a65c532fc69dc55580ee7949f to your computer and use it in GitHub Desktop.
def countPairsWithDiffK(arr, n, k):
count = 0
for i in range(0,n):
for j in range(i,n):
if (arr[i] - arr[j] == k or arr[j] - arr[i] == k ):
count = count+1
return count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment