Product Sum of Special Arrays
here, you are multiplying the depth of the &quot;parent&quot; array, instead of the nested array.
sum+=(depth)* productSum(array[i],depth+1)

try this
 sum+=(depth+1)* productSum(array[i],depth+1)

multiply it by depth+1