Given a nested array of integers, return the weighted sum of all integers. The weight of each integer is its depth in the nesting (1-indexed, where the top level is depth 1).
Multiply each integer by its depth, then return the total sum.
For example, given [1, [2, [3]]]:
1 is at depth 1, contributing 1 * 1 = 12 is at depth 2, contributing 2 * 2 = 43 is at depth 3, contributing 3 * 3 = 91 + 4 + 9 = 14You must solve this problem recursively.
nested = [1, [2, [3]]]14nested = [1, 2, 3]6nested = [[1, 1], 2, [1, 1]]10The list can be nested to any depthAll leaf values are integers in the range -10^4 to 10^4Total number of integers <= 10^3Depth is 1-indexed (top level = 1)You must use recursionRun your code to see results
Use Cmd+Enter to run