← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
Practice/LinkedIn/Leetcode 364. Nested List Weight Sum II
CodingMust
You are given a nested list of integers where each element can either be an integer or another list (which itself can contain integers or more nested lists). Your task is to calculate a weighted sum where the weight of each integer is inversely proportional to its depth.
Specifically, the weight for an integer at a given depth is calculated as: weight = maxDepth - depth + 1, where:
maxDepth is the maximum nesting level in the entire structuredepth is the current nesting level (starting at 1 for the outermost level)This means integers at deeper levels receive smaller weights, while integers closer to the surface receive larger weights.
weight = maxDepth - depth + 1Example 1:
` Input: [[1,1],2,[1,1]] Output: 8 Explanation:
Example 2:
` Input: [1,[4,[6]]] Output: 17 Explanation:
Example 3:
` Input: [1,2,3,4] Output: 10 Explanation: