Compute weighted sum of nested lists
MetaSoftware Engineer · Technical ScreenLast updated
This interview question evaluates algorithm design, data structures, correctness, complexity, edge cases, and implementation details in a realistic interview setting. A strong answer for Compute weighted sum of nested lists states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.
Given a nested collection that can contain integers or other nested collections, compute the depth-weighted sum where each integer is multiplied by its 1-based depth. Implement both DFS and BFS solutions, analyze time and space complexity, and discuss how you would adapt the approach if the weighting is inverted (deepest level has weight 1).
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.