FastPrepTree Level with the Most Nodes
Problems/Tree Level with the Most Nodes

Tree Level with the Most Nodes

Bloomberg LP logoBloomberg LP● EasyNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks for the level of a binary tree that has the most nodes, and to return that level's index. We chose three rules: levels count from zero, a tie goes to the shallowest level, and an empty tree returns -1. Our version is about 80% the same as the reported question.

Given the root of a binary tree, return the zero-based depth that contains the greatest number of non-null nodes.

The root is at depth 0. If several depths contain the same maximum number of nodes, return the shallowest such depth. Return -1 for an empty tree.

Function

widestLevel(root: TreeNode) → int

Examples

Example 1

root = [1,2,3,4,5,null,7]return = 2
root
124537

The level sizes are 1, 2, and 3, so depth 2 contains the most nodes.

Example 2

root = [1,2,3,4,null,null,5]return = 1
root
12435

Depths 1 and 2 each contain two nodes. The shallower tied depth is 1.

Example 3

root = []return = -1
root
empty

An empty tree has no level.

Constraints

  • The tree contains at most 100000 nodes.
  • -100000 <= Node.val <= 100000.

More Bloomberg LP Onsite Interview questions

  • Pascal's TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Valid Triangle NumberPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Top K Frequent WordsONSITE INTERVIEW · Seen Nov 2026
  • Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Diameter of Binary TreeeBay · ONSITE INTERVIEWeBay interview questions
  • Maximum Depth of Binary TreeLinkedIn · PHONE SCREEN · ONSITE INTERVIEWLinkedIn interview questions
  • Symmetric Binary TreeFigma · ONSITE INTERVIEWFigma interview questions
  • Mirror Image Binary TreesExpedia · ONSITE INTERVIEWExpedia interview questions
  • Mirror a Binary TreeAMD · ONSITE INTERVIEWAMD interview questions
  • Symmetric TreeZillow · ONSITE INTERVIEWZillow interview questions
  • Find a Node’s Level in an N-ary TreeMorgan Stanley · ONSITE INTERVIEWMorgan Stanley interview questions
  • Symmetric Binary TreeCapital One · ONSITE INTERVIEWCapital One interview questions
  • Serialize and Deserialize a Binary TreeAmazon · ONSITE INTERVIEW
  • Delete Nodes and Return Forest RootsGoogle · ONSITE INTERVIEWGoogle interview questions

Interview reports that mention this question

  • Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)
  • Bloomberg New Grad VOs: 32 Experiences (Part 5 of 5)

Bloomberg LP interview experiences

  • Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
  • Bloomberg SWE Intern Interview Questions: 68 Questions
  • Bloomberg Interview Questions, Level Not Reported: 65 Questions
  • Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
All Bloomberg LP interview questionsSee Bloomberg LP 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 widestLevel(TreeNode root) {
        // Write your code here.
    }

}
Checking account…