Last active
March 21, 2019 08:27
-
-
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
This file contains 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
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