As reported: Amazon SDE-1 (April 2025), round 1 with two SDE-1 interviewers, second question after Heaters.
Given the root of a binary tree, return its maximum width: the largest width among all levels. The width of a level is the number of positions between its leftmost and rightmost non-null nodes (inclusive) as if the tree were complete — null positions between them count.
This is LeetCode 662 — Maximum Width of Binary Tree.
Example 1
root = [1,3,2,5,3,null,9]
Output: 4 level 3: 5, 3, null, 9
Example 2
root = [1,3,null,5,3]
Output: 2 level 3: 5, 3
Example 3
root = [1,3,2,5]
Output: 2
Constraints: 1 ≤ number of nodes ≤ 3000; −100 ≤ Node.val ≤ 100; the answer fits in a 32-bit signed integer.
Code runner format: one line: root in LeetCode's level-order format. Implement widthOfBinaryTree(root); the harness prints the result.