FastPrepLevel of the Minimum-Sum Subtree
Problems/Level of the Minimum-Sum Subtree

Level of the Minimum-Sum Subtree

PeopleStrong logoPeopleStrong● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a PeopleStrong phone screen. The report only gives a short prompt about the level of the subtree with the smallest sum. This version says that each subtree is rooted at a node, that depth starts at zero, and that ties go to the shallower level. We chose those details and the limits. Our version is about 75% the same as the reported question.

For this exercise, assume a binary tree with signed integer values. The subtree rooted at a node contains that node and all its descendants. Find the nonempty subtree with the smallest sum of node values. Return the depth of that subtree’s root.

The whole tree's root has depth 0. If several subtrees have the same smallest sum, return the smallest root depth. Return -1 for an empty tree. The input is serialized in level order with null for missing children.

Function

minimumSubtreeLevel(root: TreeNode) → int

Examples

Example 1

root = [5,-4,2,-3,1]return = 1
root
5-4-312

The subtree rooted at -4 sums to -6, smaller than every other subtree sum. Its root is at depth 1.

Example 2

root = [0,0,0]return = 0
root
000

Every subtree sum is zero. The shallowest minimum-sum root is the whole tree's root at depth 0.

Constraints

  • For this exercise, assume the tree contains 0 to 1000 nodes.
  • Node values are integers from -10^9 through 10^9, and may repeat.
  • Use 64-bit subtree sums.

More PeopleStrong Phone Screen questions

  • Reverse Linked-List Nodes in Groups of KOA · PHONE SCREEN · Seen Mar 2026
  • Ceiling Value in a Sorted ArrayPHONE SCREEN · Seen Sep 2025
  • Maximum Employee Salary for a CompanyPHONE SCREEN · Seen Sep 2025
  • Valid ParenthesesPHONE SCREEN · Seen Sep 2025
  • Number of ProvincesPHONE SCREEN · Seen May 2025
  • Shortest Subarray with an Exact Target SumPHONE SCREEN · Seen May 2025
  • Add Forward Linked-List Numbers Using RecursionPHONE SCREEN · Seen Oct 2021
  • Running Median of a StreamPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2021
  • Build an Expression Tree from PostfixPHONE SCREEN · Seen Oct 2021
  • Maximum Score from Deleting Neighboring ValuesPHONE SCREEN · Seen Oct 2021

Similar questions at other companies

  • N-ary Index-Path Encoder and DecoderBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • House Robber IIIOkta · PHONE SCREENOkta interview questions
  • Render a Task Tree from CSV RowsStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
  • Validate Binary Search TreeKotak Mahindra Bank · PHONE SCREENKotak Mahindra Bank interview questions
  • House Robber IIIGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
  • Binary Tree Target-Sum PathsByteDance · PHONE SCREENByteDance interview questions
  • House Robber IIIVisa · PHONE SCREENVisa interview questions
  • Find All Paths for a Name in a File SystemThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions
  • Validate a BST with a Custom ComparisonApple · PHONE SCREENApple interview questions
  • Filter Undesired Comments and Their DescendantsReddit · PHONE SCREEN · ONSITE INTERVIEWReddit interview questions

Interview reports that mention this question

  • PeopleStrong SDE OA and Interview Questions: 12 Experiences
All PeopleStrong interview questionsSee PeopleStrong hiring insights
Saved
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public int minimumSubtreeLevel(TreeNode root) {
        // Write your solution here.
    }
}
Checking account…