FastPrepNested List Weight Sum (for E4)
Problems/Nested List Weight Sum (for E4)

Nested List Weight Sum (for E4)

Meta logoMeta● EasyFULLTIMEPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: We keep the weighted-depth task and the original examples. The report names nested list weight sum but gives no function you can call. Here, the same nested values are read as JSON text. Our version is about 95% the same as the reported question.

You are given a valid JSON string nestedList encoding a nested list of integers. Each list element is an integer or another list. Return the sum of every integer multiplied by the number of enclosing lists. Integers directly inside the outer list have depth 1.

For this exercise, use the JSON text as the portable input representation. Spaces may occur between tokens. Empty inner lists contribute zero. The outer list has between 1 and 50 elements, integer values are from -100 through 100, and integer depth is at most 50.

Function

depthSum(nestedList: String) → int

Examples

Example 1

nestedList = "[[1,1],2,[1,1]]"return = 10

Four 1s are at depth 2, and 2 is at depth 1. The weighted sum is 1 × 2 + 1 × 2 + 2 × 1 + 1 × 2 + 1 × 2 = 10.

Example 2

nestedList = "[1,[4,[6]]]"return = 27

The value 1 is at depth 1, 4 is at depth 2, and 6 is at depth 3. The weighted sum is 1 × 1 + 4 × 2 + 6 × 3 = 27.

Example 3

nestedList = "[0]"return = 0

The value 0 is at depth 1, so the weighted sum is 0 × 1 = 0.

Constraints

  • The string is valid nested-list JSON containing only integer values, lists, commas, and optional spaces.
  • The decoded outer list contains 1 through 50 elements.
  • Every integer is in [-100,100], and maximum integer depth is 50.
  • For this exercise, assume the JSON text has at most 100000 characters.

More Meta Phone Screen questions

  • Convert a Sorted Linked List to a Balanced BSTPHONE SCREEN · Seen Nov 2026
  • Fuzzy Word Lookup With One Misspelled LetterPHONE SCREEN · Seen Nov 2026
  • Multi-Head Attention Forward PassPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Run-Length Encoded Vector Dot ProductPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Mutual-Friend RecommendationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Best Time to Buy and Sell StockPHONE SCREEN · Seen Nov 2026
  • First Element Greater Than KPHONE SCREEN · Seen Nov 2026
  • Count Events in Rolling Minute WindowsPHONE SCREEN · Seen Oct 2026
  • Valid Word AbbreviationPHONE SCREEN · Seen Oct 2026
  • Shortest Path in a Binary MatrixPHONE SCREEN · Seen Sep 2026

Similar questions at other companies

  • Maximum Value in a Binary TreeAkuna Capital · PHONE SCREENAkuna Capital interview questions
  • Balanced Binary TreeGoogle · PHONE SCREENGoogle interview questions
  • Height-Balanced Binary TreeExpedia · ONSITE INTERVIEWExpedia interview questions
  • Maximum Root-to-Leaf Sum in a BSTZillow · PHONE SCREENZillow interview questions
  • Binary Tree Target-Sum PathsByteDance · PHONE SCREENByteDance interview questions
  • Maximum Root-to-Leaf and Leaf-to-Leaf Path SumsAmazon · ONSITE INTERVIEW
  • Nested Substitutions with Cycle DetectionKikoff · PHONE SCREENKikoff interview questions
  • Nested JSON Schema ValidatorPinterest · ONSITE INTERVIEWPinterest interview questions
  • Validate Binary Search TreeLyft · PHONE SCREENLyft interview questions
  • Lowest Common Ancestor Only When Both Targets ExistAdobe · ONSITE INTERVIEWAdobe interview questions

Meta interview experiences

  • Meta PhD SWE Intern AI Coding Phone Screen: 1 Experience
  • Meta Business Support Engineer Phone Screen: 1 Experience
  • Meta Software Engineer Onsite Questions: 3 Experiences
  • Meta AI Native Engineer OA and Onsite: 1 Experience
  • Meta AI-Native Coding Interview: 3 Experiences
  • Meta Production Engineer Intern Questions: 6 Experiences
All Meta interview questionsSee Meta hiring insights
Saved
class Solution {
    public int depthSum(String nestedList) {
        // Write your code here
    }
}
Checking account…