Question bank › Recursion
Dsa Recursion Easy

The Weighted Nested Sum

Given a nested list of integers (as a string), calculate the 'Weighted Sum'. The weight of an integer is its nesting depth. For example, in '[10, [20, 30], 5]', 10 and 5 are at depth 1, while 20 and 30 are at depth 2. The sum is (10*1) + (20*2) + (30*2) + (5*1) = 115. Brackets '[]' define the nesting. Commas and spaces may be present. Input Format: A string representing the nested list. Output Format: A single integer. Example: Input: [1, [2, [3]]] Output: 14 (Explanation: 1*1 + 2*2 + 3*3 = 14)

Key concepts

recursionparsingdepth-first processing

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.