PIXELBANKv9.1.0
Menu

Given a nested list of integers, return the sum where each integer is multiplied by its depth. The outermost list is depth 1.

Input: nested list as JSON string.

Example:

Input:
[[1,1],2,[1,1]]
Output:
10
Reasoning:
  • The input [[1,1],2,[1,1]] is a nested list with integers at different depths.
  • We calculate the weighted sum by multiplying each integer by its depth:
    • The inner lists [1,1] are at depth 2, so their integers contribute 1â‹…2+1â‹…2=41 \cdot 2 + 1 \cdot 2 = 4 each.
    • The integer 2 is at depth 1, so it contributes 2â‹…1=22 \cdot 1 = 2.
    • The last inner list [1,1] is also at depth 2, contributing another 1â‹…2+1â‹…2=41 \cdot 2 + 1 \cdot 2 = 4.
  • The total sum is then calculated as 4+2+4=104 + 2 + 4 = 10.
  • The final output is 1010.

Constraints:

  • 1 <= total elements <= 50
  • Nesting depth <= 50
  • -100 <= integer value <= 100
solution.py

Test Results

0/0
Run code to see test results.
Nested List Weight Sum - Medium | PixelBank