FastPrepLevel of a Node in a Binary Tree
Problems/Level of a Node in a Binary Tree

Level of a Node in a Binary Tree

Bloomberg LP logoBloomberg LP● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A report from a Bloomberg software engineer loop in Frankfurt in March 2025 names one question: use a breadth-first search to tell how deep a given node sits below the root. It gives no signature, limits or example, and does not say which of the coding rounds it mentions (there were two) asked it.

Everything else here is our practice choice. The tree is a binary tree given by its root, every node value is different, and the target value is always in the tree. The root is on level 1 and each child is one level below its parent. The values are in no particular order, the tree has 1 to 500 nodes, and values are from -10,000 to 10,000.

The judged task matches the report at about 85%.

You are given the root of a binary tree and an integer target. Every node holds a different value, and exactly one node holds target.

The root is on level 1. Its children are on level 2, their children are on level 3, and so on: a node's level is one more than its parent's level.

Return the level of the node whose value is target. The tree is not a binary search tree, so the values can be in any order.

Function

levelOfNode(root: TreeNode, target: int) → int

Examples

Example 1

root = [5,2,9,null,4,7,null,null,null,6]target = 6return = 4
root
524976

Level 1 holds the root 5. Level 2 holds 2 and 9. Level 3 holds 4 (the right child of 2) and 7 (the left child of 9). Level 4 holds 6, the left child of 7. So the answer is 4.

Example 2

root = [1,2,3,4,5]target = 3return = 2
root
12453

3 is a child of the root 1, so it is on level 2.

Example 3

root = [10,-3,null,20]target = 20return = 3
root
10-320

The path from the root is 10, then -3, then 20. That is three nodes, so the answer is 3. Notice that 20 is larger than the root 10 but sits on its left side. The values are not in search-tree order, so you cannot use their size to choose a direction.

Constraints

  • The tree has between 1 and 500 nodes.
  • -10000 <= Node.val, target <= 10000
  • All node values are different, and exactly one node has the value target.

More Bloomberg LP Phone Screen questions

  • N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
  • Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
  • Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
  • Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Sparse Vector and Matrix OperationsPHONE SCREEN · Seen Oct 2026
  • Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Symmetric Binary TreeDocuSign · PHONE SCREENDocuSign interview questions
  • Maximum Depth of Binary TreeLinkedIn · PHONE SCREEN · ONSITE INTERVIEWLinkedIn interview questions
  • Nodes at a Given N-ary Tree LevelAmazon · PHONE SCREEN
  • Binary Tree Level-Order Traversal by LevelsAdobe · PHONE SCREEN · ONSITE INTERVIEWAdobe interview questions
  • Left View of a Binary TreeMygate · PHONE SCREENMygate interview questions
  • Invert a Binary TreeCapital One · PHONE SCREENCapital One interview questions
  • Maximum-Scoring Consecutive Tree LevelsJane Street · PHONE SCREENJane Street interview questions
  • Minimum Edits to a Perfect Binary TreeSnowflake · PHONE SCREENSnowflake interview questions
  • Find All Paths for a Name in a File SystemThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions
  • Check a Complete Binary TreeGoldman Sachs · PHONE SCREENGoldman Sachs interview questions

Bloomberg LP interview experiences

  • Bloomberg SWE Phone Screen and Onsite: 1 Experience
  • Bloomberg SWE Phone Screens with Two Teams: 1 Experience
  • Bloomberg AI Interview, Hiring Level Not Reported: 2 Experiences
  • Bloomberg Experienced SWE AI Coding Interviews: 2 Experiences
  • Bloomberg New Grad AI-Assisted Coding Rounds: 3 Experiences
  • Bloomberg New Grad SWE AI-Assisted Coding Rounds: 1 Experience
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 levelOfNode(TreeNode root, int target) {
        // Write your code here.
    }
}
Checking account…