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
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Easy

0

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
Recursion
DFS
BFS
Nested data structures
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported