Tap here to switch tabs
Problem
Submissions

Problem: Maximum Width of Binary Tree

med
30 min
Try to solve the Maximum Width of Binary Tree problem.

Statement

Given the root of a binary tree, compute the maximum width among all levels of the tree.

The width of a level is defined as the number of positions between the leftmost and rightmost non null nodes at that level, inclusive. When measuring width, treat the tree as if it were a complete binary tree, so missing children between existing nodes still count as positions.

Return the maximum width over all levels.

Note: Null nodes at the ends of a level are not counted, but null positions between two non null nodes are counted.

Constraints:

  • The number of nodes in the tree is in the range [1,3000][1, 3000]

  • −100≤-100 \leq Node.val ≤100\leq 100

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Width of Binary Tree

med
30 min
Try to solve the Maximum Width of Binary Tree problem.

Statement

Given the root of a binary tree, compute the maximum width among all levels of the tree.

The width of a level is defined as the number of positions between the leftmost and rightmost non null nodes at that level, inclusive. When measuring width, treat the tree as if it were a complete binary tree, so missing children between existing nodes still count as positions.

Return the maximum width over all levels.

Note: Null nodes at the ends of a level are not counted, but null positions between two non null nodes are counted.

Constraints:

  • The number of nodes in the tree is in the range [1,3000][1, 3000]

  • −100≤-100 \leq Node.val ≤100\leq 100