Skip to content

Instantly share code, notes, and snippets.

@MaxMonteil
Created April 2, 2019 18:20
Show Gist options
  • Save MaxMonteil/659e2fb99f86f68db8d292ce87d77dbc to your computer and use it in GitHub Desktop.
Save MaxMonteil/659e2fb99f86f68db8d292ce87d77dbc to your computer and use it in GitHub Desktop.
Given an array arr, find element pairs whose sum equal the second argument arg and return the sum of their indices.
def pairwise(arr, arg):
size = range(len(arr))
s = 0
for i in size:
for j in size:
if arr[i] + arr[j] == arg:
arr[i] = 0
arr[j] = 0
s = s + i + j
return s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment