Maximum Width of Binary Tree

Medium · Trees · about 20 minutes

Asked at Amazon, Google, Bloomberg, Meta, Microsoft.

Place the tree's nodes in the slots they would occupy in a complete binary tree. For each level, the width is the number of slots from its leftmost real node to its rightmost real node, empty slots in between included. Return the largest width over all levels; it fits in a signed 32-bit integer.

Related guides