Amazon Germany Interview Question (Junior Level) - Can anyone solve this?
Anonymous User
823

Recently had an online assessment with Amazon in a German city and they asked this question, followed up with 2 other questions. I couldn't solve it properly, but was wondering if someone had an answer to this. I don't remember the exact question, but this is what I can basically recall.

You have a deeply nested list like [1, [12, [12, [13, [34, [42, [45, [76, [98, 234]]]]]]]]]. How do you print out the sum and average at each level in this format, starting from the innermost list and working your way up

[98, 234] sum=332 avg=166
[76, [98, 234]] sum=408 avg=204 # the avg is calculated as (76) + (332) / 2
[45, [76, [98, 234]]] sum=453 avg=226.5
...

They also said to not assume the sublists will only contain 1 non-list element and 1 list element. There could be any number of list types and non-list types inside a sublist.

The other two questions were ones I had seen before on leetcode so it was nothing special. But I couldn't find a proper solution to this one within the time limit.

Comments (7)