Search⌘ K
AI Features

Solution: Maximum Width of Binary Tree

C# solution for the Maximum Width of Binary Tree problem using the Tree Breadth-First Search pattern.

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] ...