root of a non-empty binary tree.
The width of a level is the number of positions from its leftmost node to its rightmost node inclusive, counting the empty spots in between as well: the places where nodes would be if the tree were complete down to that level.
Return the largest width over all levels.root=tree_node([8, 2, 6, None, 4, 5, None]) → 2
Level 2 holds 4 (the right child of 2) and 5 (the left child of 6). Nothing lies between them, so the width is 2.
root=tree_node([1, 7, 3, 9, None, None, 2]) → 4
On level 2 the outer nodes are 9 and 2; a complete tree would fit two more nodes between them, so the width is 4.
root=tree_node([0]) → 1
root=tree_node([8, 2, 6, None, 4, 5, None])
2
Run checks the first 3 tests in your browser. Submit checks all 98 tests on the server, hidden ones included.