Thoughts about 3rd solution?



I came up with the following solution (O(n) as well):

def findProduct(arr):
  product = 1
  for x in arr:
    product *= x

  for i in range(len(arr)):
    arr[i] = product / arr[i]
  return arr

Sure, there’s an extra multiplication/division here, but do you think it is appropriate? If not, why?


Hey Dennis,

Thanks for reaching out! This is actually a good solution for Python in my opinion. It takes O(1) space and O(n) time.

If you have any other questions/comments/suggestions, let us know!


This fails on any input with 0.


Thank you. Need to double-check everything…