FastPrepWidest Level of a Binary Tree
Problems/Widest Level of a Binary Tree

Widest Level of a Binary Tree

Adobe logoAdobe● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: You find the level of a binary tree that spans the most positions, counting gaps. A May 2022 report describes an Adobe Computer Scientist loop in Bengaluru that ended in rejection after the later rounds. Its opening DSA round had two linked tasks. The first was counting islands in a grid, and the second was this classic one. The author is a senior engineer with over six years of experience, and says they finished the pair early. The post only gives the link.

The rules are those of the linked task, including its promise that the answer fits in a signed 32-bit integer. We chose these limits: 1 to 1000 nodes, with values from -100 to 100. The values do not change the answer. We wrote new examples.

Our version is about 90% the same as the reported question.

Given the root of a binary tree, return the width of its widest level.

To measure a level, number the spots of the tree as in a complete binary tree: the root is at position 1, and the spot at position p has two child spots, at 2p and 2p + 1. This holds for every spot above the level, empty or not, so an empty spot still has two (empty) child spots below it. The width of a level is the position of its rightmost node minus the position of its leftmost node, plus 1. So empty spots between two nodes of the level count, but empty spots outside them do not. The node values do not affect the answer.

Function

widestLevel(root: TreeNode) → int

Examples

Example 1

root = [4,2,7,1,null,null,9]return = 4
root
42179

Level 2 holds 1, then two empty spots (the right child of 2 and the left child of 7), then 9. Counting from 1 to 9 with the empty spots gives a width of 4, the largest level. The answer is 4.

Example 2

root = [4,2,7,1,3,6]return = 3
root
421376

Level 1 has width 2. Level 2 holds 1, 3 and 6 side by side, a width of 3; the missing right child of 7 is after the last node, so it is not counted. The answer is 3.

Example 3

root = [5,null,8,null,6]return = 1
root
586

Every level has only one node, so every width is 1.

Example 4

root = [0,-20,20,null,-10,10,null,-15,null,null,15,null,-12,12]return = 6
root
0-20-10-15-1220101512

Positions: 0 at 1; -20 at 2 and 20 at 3; -10 at 5 and 10 at 6; -15 at 10 and 15 at 13; -12 at 21 and 12 at 26. The empty spots 11 and 12 on level 3 still have child spots (22, 23, 24 and 25), and those sit between -12 and 12. So the bottom level has width 26 - 21 + 1 = 6. The level widths are 1, 2, 2, 4 and 6, so the answer is 6.

Constraints

  • The tree has 1 to 1000 nodes.
  • -100 <= Node.val <= 100
  • The answer is at most 2^31 - 1.

More Adobe Phone Screen questions

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
  • Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
  • Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
  • Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
  • Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
  • Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
  • Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026

Similar questions at other companies

  • 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
  • Binary Tree Spiral Level OrderAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Check a Complete Binary TreeGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
  • Binary Tree Right Side ViewGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Same Binary TreeOdoo · PHONE SCREENOdoo interview questions
  • Binary Tree Zigzag Level Order TraversalLinkedIn · PHONE SCREEN · ONSITE INTERVIEWLinkedIn interview questions
  • Insert an Employee into an Organization HierarchyWaymo · PHONE SCREENWaymo interview questions
  • Bottom View of a Binary TreeOracle · PHONE SCREEN · ONSITE INTERVIEWOracle interview questions

Interview reports that mention this question

  • Adobe CS1 Interviews: 14 Experiences (Part 4 of 6)

Adobe interview experiences

  • Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
  • Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
  • Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
  • Adobe New Grad MTS Interview Questions: 7 Experiences
  • Adobe ML/Research Intern Interviews: 12 Experiences (Part 4 of 4)
All Adobe interview questionsSee Adobe 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…