Skip to content

Instantly share code, notes, and snippets.

@woodRock
Last active March 21, 2019 08:27
Show Gist options
  • Save woodRock/1cbfa071d2e49b91893a28233ebf99d6 to your computer and use it in GitHub Desktop.
Save woodRock/1cbfa071d2e49b91893a28233ebf99d6 to your computer and use it in GitHub Desktop.
Given an array of integers, return a new value such that each elemnent at index i of the new array is a product of all the numbers in the original array except the one at i
def arrayProduct(a=[],*args):
result = [0] * len(a)
product = 1
for i in range (0,len(a)):
product = product * a[i]
for j in range (0,len(a)):
result[j] = product / a[j]
return result
a = [1,2,3,4,5]
print(arrayProduct(a))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment