interview_problems.ipynb 2.0 KB

### Problem 1 Given an array, find out the product of its element using recursion. - Input: [1, 2, 3, 4, 5] - Output: 120
def productOfArray(arr):
    """
    calculates the product of all the numbers in array
    """
    if len(arr) == 0:
        return 1
    else:
        return len(arr) * productOfArray(arr[1:])

productOfArray([1, 2, 3, 4, 5])
20