This was a facebook online coding session for an internship. We didn't run any code. Interviewer just wanted a general idea on how to solve the problem. The question goes like so...
Given a nested array
e.g [8, 2, [ 5,9, [6] ,7], [1, [ [ 4, [3] ] ] ]
find the sum of all numbers multiplied by their depth
so for the array above: sum = 8*1 + 2*1 + 5*2 + 9*2 + 6*3 + 7*2 + 1*3 + 4*5 + 5*6
8 , 2 is in level 1
5, 9 is in level 2
6 is in level in 3
.
.
3 is in level 6
I know implementing DFS with a count variable is a solution but i was wondering if anyone has encountered something similar on leetcode or hackerrank