Answers for "Replace each element of an array with product of every other element without using division operator"

0

Replace each element of an array with product of every other element without using division operator

def findProduct(A, n, left=1, i=0):
 
    # base case: no elements left on the right
    if i == n:
        return 1
 
    # take backup of the current element
    curr = A[i]
 
    # calculate the product of the right sublist
    right = findProduct(A, n, left * A[i], i + 1)
 
    # replace the current element with the product of the left and right sublist
    A[i] = left * right
 
    # return product of right the sublist, including the current element
    return curr * right
Posted by: Guest on February-02-2021

Code answers related to "Replace each element of an array with product of every other element without using division operator"

Browse Popular Code Answers by Language