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

Open every published interview problem, solution, scene, and memory room free, with no account.

More Backtracking problems