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.
1 parent b11a911 commit cc784a8Copy full SHA for cc784a8
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