<jupyter_start><jupyter_text>Product Sum[link](https://www.algoexpert.io/questions/Product%20Sum)  My Solution<jupyter_code>def productSum(array):
    # Write your code here.
    return productSumHelper(array, 1)

def productSumHelper(element, depth):
	if type(element) is list:
		listSum = 0
		for x in element:
			listSum += productSumHelper(x, depth + 1)
		return depth * listSum
	else:
		# element is an integer
		return element
def productSum(array):
    # Write your code here.
    return productSumHelper(array, 1)

def productSumHelper(array, depth):
    currentSum = 0
    for x in array:
        if type(x) is list:
            currentSum += productSumHelper(x, depth + 1)
        else:
            currentSum += x
    return depth * currentSum<jupyter_output><empty_output><jupyter_text>Expert Solution<jupyter_code>def productSum(array, multiplier=1):
    """
    O(n) time | O(d) space where 
    n is the total number of elements in the array including sub-elements, and 
    d is the greatest depth of "special" arrays in the array
    """
    sum = 0
    for element in array:
        if type(element) is list:
            sum += productSum(element, multiplier+1)
        else:
            sum += element
    return sum * multiplier<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09233176838810642, 'fraction_numerical': 0.008607198748043818, 'mean_word_length': 3.1258064516129034, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '441802', 'license': 'MIT', 'n_tokens_mistral': 414, 'n_tokens_neox': 392, 'n_words': 122, 'path': 'algoExpert/product_sum/solution.ipynb', 'repo_name': 'maple1eaf/learning_algorithm', 'size': '1278'}