Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
657 views
in Online Assessments by Expert (108,110 points) | 657 views

1 Answer

0 like 0 dislike

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
by Expert (108,110 points)