Compute the inverse nested list weight sum in a single pass.
Unlock detailed company stats for this questionUpgrade
Given a nested list of integers where each element is an integer or another nested list, the depth of an integer is how many lists it is nested inside, and the maximum depth is that of the deepest integer. Each integer's weight is MaximumDepth - CurrentDepth + 1. Return the sum of every integer multiplied by its weight. The solution should be highly optimized, ideally one pass without first traversing the list to find the maximum depth.
Example: {1, {2, 2}, {2, {3, 2}}} has maximum depth 3. 1 at depth 1 has weight 3 (value 3); the two 2s at depth 2 have weight 2 (value 8); the other 2 at depth 2 has weight 2 (value 4); {3, 2} at depth 3 has weight 1 (value 5). Total output: 20.
Community answers
No answers contributed by the community yet.
Related questions
Compute the reverse-depth weighted sum of a nested list.Nested List Weight Sum II.Nested List Weight Sum.Related courses

Course

Course
Course
