Skip to content

Commit 9ae429e

Browse files
authored
Merge pull request #4 from sriramanvellingiri/product-sum
2 parents 9dcf003 + cc784a8 commit 9ae429e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

recursion-product-sum.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)