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

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Backtracking problems