859. Check if Binary Tree is Complete

EasyTreesBinary TreeBFS

Given the root of a binary tree, determine whether it is complete — every level is fully filled except possibly the last, which is filled from left to right with no gaps. Return true or false. The tree is given as a level-order array with null for missing children.

Input: A level-order array of the tree.

Output: Boolean — true or false.

Examples

Example 1
Input: [1,2,3,4,5,6]
Output: true
Explanation: All levels filled left to right.
Example 2
Input: [1,2,3,4,5,null,7]
Output: false
Explanation: A gap appears before later nodes.
Example 3
Input: [1]
Output: true
Explanation: Single node.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →