← LinkedIn Interview Insights

LinkedIn·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jul 2026

Summary

LinkedIn SWE interview with a nested list problem that looks straightforward until you realize the weights run backwards relative to depth. One question, but it had enough hidden complexity to keep me busy for a while.

Questions Asked (1)

Q1

Given a nested list of integers where each integer has a depth based on how many lists it's inside, compute the inverse-depth weighted sum. The weight of an integer at depth d is (max_depth - d + 1), so deeper integers get lower weight. Return the total weighted sum.

Algorithms & Data Structures
Author's notes

My first instinct was to just do a DFS and track depth, which is fine, but I didn't immediately clock that you need the max depth before you can assign any weights.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the problem and edge cases, then discuss a recursive DFS approach that computes the maximum depth in one pass and the weighted sum in another (or combines both). Emphasize that the weight depends on the global max depth, so you need to know it before computing the sum. Alternatively, you can compute the sum of elements multiplied by their depth and the total sum, then use the formula: weighted sum = (max_depth + 1) * total_sum - sum_of_depth_times_value.

Pro tip: Mention that you can avoid a second traversal by computing both the max depth and the weighted sum in a single DFS if you first compute the max depth, or by using the formula with two accumulators (total sum and depth-weighted sum) in one pass, then combining after the max depth is known. This shows optimization awareness.

1. Clarify the problem and constraints

Ask about input size, nesting depth limits, and whether the list can be empty. Confirm that depth starts at 1 for top-level integers.

2. Choose an approach

Decide between a two-pass DFS (first find max depth, then compute weighted sum) or a one-pass DFS that computes total sum and depth-weighted sum, then combines using the formula.

3. Implement the solution

Write clean recursive code. For two-pass: first DFS to find max depth, second DFS to compute sum with weights. For one-pass: accumulate total sum and sum of value*depth, then compute weighted sum = (max_depth + 1) * total_sum - sum_depth_times_value.

4. Test with examples

Walk through a simple nested list like [1,[2,3]] and verify the output. Also test edge cases: empty list, single integer, deeply nested list.

5. Analyze complexity

State that time complexity is O(n) where n is total number of integers, and space complexity is O(d) for recursion stack where d is max depth.

Key Points to Mention

  • Depth definition: top-level integers have depth 1, each nested list increases depth by 1.
  • Weight formula: weight = max_depth - depth + 1, so deeper elements get lower weight.
  • Two-pass DFS: first pass to find max depth, second pass to compute weighted sum.
  • One-pass optimization: compute total sum and sum of value*depth, then use weighted sum = (max_depth + 1) * total_sum - sum_depth_times_value.
  • Edge cases: empty list, single element, maximum depth, negative numbers.
  • Time and space complexity: O(n) time, O(d) space for recursion.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.