This question has been asked in big MNC's. Its a good and complex example of using recursive function with logical thinking as well
Problem Statement:
"Nested List Sum with Depth Weighting"
You are given a nested list of integers. The list may contain other nested lists to an arbitrary depth. Write a recursive function to calculate the weighted sum of all integers in the list, where the weight is determined by the depth of each integer.
Weight Calculation:
The deeper the integer is nested, the higher its weight.
Weight is calculated as:
Level 1: Weight = 1
Level 2: Weight = 2
Level 3: Weight = 3
...and so on.
Example input and output
nested_list = [1, [4, [6]]]
# Explanation:
# - 1 is at depth 1 → 1 * 1 = 1
# - 4 is at depth 2 → 4 * 2 = 8
# - 6 is at depth 3 → 6 * 3 = 18
# Total Sum = 1 + 8 + 18 = 27
Output: 27
На этой странице сайта вы можете посмотреть видео онлайн Python Challenge - Nested list weight sum using recursive function & BFS длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Let's Cook the Code 02 Март 2025, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 28 раз и оно понравилось 1 зрителям. Приятного просмотра!