Dsa
Recursion
Medium
The Recursive Skipper
You are summing numbers in a nested list. However, if an element is a sub-list, you must evaluate the sum of that sub-list first. Let that sum be 'S'. After processing the sub-list, you must skip the next 'S % 3' elements in the current list level.
Input: A string representing a nested list of integers.
Output: The total sum of all processed elements.
Example:
Input: [10, [2, 1], 5, 8]
1. Process 10 (Sum=10)
2. Process sub-list [2, 1]. Sum=3.
3. Since S=3, skip next 3 % 3 = 0 elements.
4. Process 5 (Sum=10+3+5=18)
5. Process 8 (Sum=18+8=26)
Output: 26
Example 2: [10, [5], 2, 1]
1. 10.
2. [5] returns 5.
3. Skip 5 % 3 = 2 elements (skips 2 and 1).
Output: 15
Key concepts
recursionnested structuresflow control
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