Skip to content

Instantly share code, notes, and snippets.

@wenweixu
Created September 2, 2019 23:07
Show Gist options
  • Save wenweixu/1f1cd5ad3a0ae8a908c5aa5d41a65117 to your computer and use it in GitHub Desktop.
Save wenweixu/1f1cd5ad3a0ae8a908c5aa5d41a65117 to your computer and use it in GitHub Desktop.
Hackerrank Pairs Python solution
# Complete the pairs function below.
def pairs(k, arr):
my_dict = {}
result = 0
for ele in arr:
my_dict[ele] = 1
if ele + k in my_dict:
result += 1
if ele -k in my_dict:
result += 1
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment