← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
Nested List Weight Sum is a classic Meta (Facebook) interview problem involving a nested list of integers and sublists. Each integer contributes to the total sum based on its depth (multiplied by its nesting level), solvable via DFS recursion, BFS level-order traversal, or iterative stack approaches.[1][3][7]
Given a nested list of integers, return the sum of all integers in the list weighted by their depth. Depth starts at 1 for the outermost level and increases by 1 for each nested level. Each NestedInteger can be either an integer or a list of NestedIntegers.[3][8][1]
The standard example input is [[1,1],2,[1,1]]:
2 → contributes 2 * 1 = 21s → each contributes 1 * 2 = 2 (total 8)10[5][3]Another common example is [1,[4,[6]]]:
1 → 1 * 1 = 14 → 4 * 2 = 86 → 6 * 3 = 1827[9]For [1,[2,2],[[3],2],1]:
1 and last 1 → 1*1 + 1*1 = 22s → 2*2 + 2*2 = 83 → 3*3 = 919 (adjusted from some sources showing depth-multiplied sums).[8]1 <= nestedList.length <= 50[-100, 100]isInteger(), getInteger(), getList()[2][1][3]