Check if complete tree

Medium

Check if a given binary tree is completed. A complete binary tree is one in which every level of the binary tree is completely filled except possibly the last level. Furthermore, all nodes are as far left as possible.

Examples

5

/ \

3 8

/ \

1 4

is completed.

5

/ \

3 8

/ \ \

1 4 11

is not completed.

Corner Cases

  • What if the binary tree is null? Return true in this case.

Recursive: Check if index should not exist

BFS: toggle boolean on first node doesn't have both children

Last updated

Was this helpful?