Easy · Backtracking

Nested List Weight Sum

Given a nested list whose elements are integers or further nested lists, return the sum of each integer multiplied by its depth, where integers in the outermost list have depth 1.

Examples

Example 1

[[1,1],2,[1,1]]

Output: sum = 10

Example 2

[1,[4,[6]]]

Output: sum = 27

Rebuild it in the studio

Core interview problems are free with a full runner and lessons; Pro opens the complete library.

More Backtracking problems