We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 9dcf003 + cc784a8 commit 9ae429eCopy full SHA for 9ae429e
recursion-product-sum.py
@@ -0,0 +1,11 @@
1
+# O(n) time | O(d) - where n is the total number of elements in the array,
2
+# including sub-elements and d is the greatest depth of arrays in the array
3
+def productSum(array, multiplier=1):
4
+ # Write your code here.
5
+ sum = 0
6
+ for element in array:
7
+ if type(element) is list:
8
+ sum += productSum(element, multiplier + 1)
9
+ else:
10
+ sum += element
11
+ return sum * multiplier
0 commit comments