Weighted Depth Sum of Nested Comment Scores
Last updated: November 29, 2026
Quick Overview
Comment scores are stored as a nested list where each element is either an integer or another list. Return the sum of every integer multiplied by its nesting depth, where top-level integers have depth 1.
Meta
November 29, 20260
0
0 solved
Comment scores are stored as a nested list where each element is either an integer or another list. Return the sum of every integer multiplied by its nesting depth, where top-level integers have depth 1.
Comment threads on Facebook are naturally nested, and this question checks basic recursion or BFS over a heterogeneous structure. Meta interviewers usually want you to state the depth convention, code it quickly, and then discuss the iterative version to avoid recursion limits.
What the Interviewer Expects
- Confirms the depth convention and what an empty list contributes
- Implements DFS that passes depth down, or BFS by level
- Distinguishes integers from lists cleanly
- Discusses recursion depth limits for pathological nesting
- Gives correct complexity in terms of total elements
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you compute the inverse weighting, where the deepest level has weight 1?
- Rewrite it iteratively without recursion.
- What if the structure is exposed only through an iterator interface?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input is a Python list whose elements are ints or lists. Integers at the top level count once, integers inside one list count twice, and so on. Empty lists contribute 0. Output is an integer. Aim for ...
High-Level Design
BFS by level is the most direct: process the current level, add depth * value for each integer, and gather the elements of every inner list into the next level. This also avoids Python's recursion l...