PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/LinkedIn

Compute inverse-depth weighted sum of nested lists

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of nested list traversal, depth computation, and weighted aggregation by the inverse of depth, focusing on concepts like maximum depth calculation and applying weights across hierarchical integer elements.

  • medium
  • LinkedIn
  • Coding & Algorithms
  • Software Engineer

Compute inverse-depth weighted sum of nested lists

Company: LinkedIn

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Inverse-Depth Weighted Sum of a Nested List You are given a **nested list** of integers. Each element is either: - an integer, or - another nested list. Define the **depth** of an integer as the number of lists it is inside (top-level integers have depth 1). Compute the **inverse-depth weighted sum**: - Let `D` be the **maximum depth** in the structure. - An integer at depth `d` has weight `D - d + 1`. - Return the sum of `value * weight` over all integers. ### Input - A nested list structure (you may assume an interface like: - `isInteger()`, `getInteger()`, `getList()`), or an equivalent representation. ### Output - An integer: the inverse-depth weighted sum. ### Example Input: `[1, [4, [6]]]` - Depths: `1` at depth 1, `4` at depth 2, `6` at depth 3. Max depth `D=3`. - Weights: depth1 -> 3, depth2 -> 2, depth3 -> 1 - Sum = `1*3 + 4*2 + 6*1 = 17` ### Constraints - Total number of integers across all lists can be up to e.g. `10^4`. - Integers fit in 32-bit signed range.

Quick Answer: This question evaluates understanding of nested list traversal, depth computation, and weighted aggregation by the inverse of depth, focusing on concepts like maximum depth calculation and applying weights across hierarchical integer elements.

Related Interview Questions

  • Count Trips From Vehicle Logs - LinkedIn (easy)
  • Design O(1) Randomized Multiset - LinkedIn (easy)
  • Process Mutable Matrix Sum Queries - LinkedIn (medium)
  • Design a Randomized Multiset - LinkedIn (medium)
  • Can You Place N Objects? - LinkedIn (medium)
LinkedIn logo
LinkedIn
Feb 11, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
14
0

Inverse-Depth Weighted Sum of a Nested List

You are given a nested list of integers. Each element is either:

  • an integer, or
  • another nested list.

Define the depth of an integer as the number of lists it is inside (top-level integers have depth 1).

Compute the inverse-depth weighted sum:

  • Let D be the maximum depth in the structure.
  • An integer at depth d has weight D - d + 1 .
  • Return the sum of value * weight over all integers.

Input

  • A nested list structure (you may assume an interface like:
    • isInteger() , getInteger() , getList() ), or an equivalent representation.

Output

  • An integer: the inverse-depth weighted sum.

Example

Input: [1, [4, [6]]]

  • Depths: 1 at depth 1, 4 at depth 2, 6 at depth 3. Max depth D=3 .
  • Weights: depth1 -> 3, depth2 -> 2, depth3 -> 1
  • Sum = 1*3 + 4*2 + 6*1 = 17

Constraints

  • Total number of integers across all lists can be up to e.g. 10^4 .
  • Integers fit in 32-bit signed range.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More LinkedIn•More Software Engineer•LinkedIn Software Engineer•LinkedIn Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.