Reported September 2026
LinkedInstring

Inverse-Depth Nested List Sum

Reported by candidates from LinkedIn's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live LinkedIn OA. Under 2s to a working solution.
Founder's read

The constraint that matters in this LinkedIn OA, reported in September 2026, is the input: a string up to 5000 characters, nesting capped at 50. Nothing there forces a clever trick. It's one pass over a bracketed string, and the only real catch is that you don't know the max depth until you've read everything. The task is inverse-depth nested list sum, an array and string parsing problem in disguise. If you blank on the parsing under the clock, StealthCoder is the safety net that runs invisibly during the live OA and hands you the approach. Here's the script.

The problem

A nested list contains signed integers and other lists. You receive its valid bracketed representation as nestedList. Compute an inverse-depth weighted sum.
An integer directly inside the outermost list has depth 1. Each enclosing nested list adds one. Let D be the greatest depth of any integer in the input. An integer with value x at depth d contributes x × (D - d + 1). Return the sum of all contributions as a 64-bit integer.
Lists use square brackets and comma-separated elements. An element is an integer or another list. Integers use ordinary base-10 notation, optionally preceded by a minus sign. There are no spaces, plus signs, or leading zeroes except the integer 0. The entire input is one list, and empty lists are allowed.
Empty lists contain no integers and do not increase D by themselves. If there are no integers anywhere, return 0. Repeated values are separate occurrences and each contributes to the sum.

Function
depthSumInverse(nestedList: String) → long

Examples
Example 1
nestedList = "[2,[3,[4]],5]"
return = 31
The deepest integer is 4 at depth 3. The sum is 2×3 + 3×2 + 4×1 + 5×3 = 31.
Example 2
nestedList = "[-2,[5],[[[]]],0]"
return = 1
The deepest integer is 5 at depth 2; the deeper empty lists do not count. The result is -2×2 + 5×1 + 0×2 = 1.

Constraints
2 <= nestedList.length <= 5000.
The representation is valid under the stated grammar.
Every integer is between -1000 and 1000.
At most 50 lists are nested simultaneously, counting the outermost list.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: don't compute weights during the scan. Parse the string once, and for every integer record its value and its depth. Track maxDepth only when you actually read an integer, since empty lists like [[[]]] must not raise D. Then the answer is the sum of value x (D - d + 1). Better yet, keep a running total of values per depth level, or use the level-sum trick: add the running prefix of all integers seen so far at each depth step. The pitfalls are parsing. Handle the minus sign, multi-digit numbers up to 1000, and flush the number on a comma or closing bracket. Use a 64-bit accumulator even though the numbers are small. Depth is at most 50, so a simple array of size 51 works. If the parsing logic slips mid-assessment, StealthCoder is the hedge that gives you a clean solution while you're live.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Inverse-Depth Nested List Sum cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as nested list weight sum ii. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass LinkedIn's OA.

LinkedIn reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Inverse-Depth Nested List Sum FAQ

How hard is the inverse-depth nested list sum really?+

Easy to medium. The idea is simple, but the string parsing has edge cases: negative numbers, multi-digit values, and empty lists. Most failures come from flushing a number at the wrong moment, not from the algorithm itself.

What's the trick to avoid two passes?+

Store a sum of values per depth in an array while parsing. At the end you know the max depth that actually held an integer, and you compute each level's weight as D - d + 1. One scan of the string, then a tiny loop over at most 50 levels.

Do empty lists change the max depth?+

No. The statement says empty lists contain no integers and don't raise D. So only update maxDepth when you finish reading a number. Example 2 shows it: the nested empty lists reach depth 4, but D stays 2.

Is this pattern still asked at LinkedIn?+

It was reported in September 2026, so nested list and parsing questions are clearly still in rotation. Expect variations: normal depth weighting, different grammar, or building the structure first. Practice reading a bracket string with a depth counter.

How do I prepare in 48 hours?+

Write the parser from scratch twice. Handle '-', digits, ',', '[' and ']' with a depth counter and a current-number buffer. Test on both examples and on '[[]]' and '[0]'. Then confirm you use a long accumulator and return 0 when no integers exist.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with LinkedIn.

OA at LinkedIn?
Invisible during screen share
Get it