You are given a nested list of integers, where each element is either:
Define the depth of an integer as the number of lists that contain it.
[1,[2,[3]]]
, the integer
1
has depth 1,
2
has depth 2, and
3
has depth 3.
Let D be the maximum depth among all integers in the structure. Compute the inverse-depth weighted sum where each integer with depth d is weighted by:
Return the total weighted sum.
[1,[2,[3]]]
D=3
1*(3-1+1) + 2*(3-2+1) + 3*(3-3+1)
=
1*3 + 2*2 + 3*1 = 10
10
[[1,1],2,[1,1]]
D=2
8
N
up to ~1e4.
int inverseDepthSum(NestedList nested)