Check Completeness of a Binary Tree
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
A binary tree is **complete** when every level except possibly the last is completely filled, and all nodes on the last level are packed as far **left** as possible (no gap may appear to the left of any node on that level).
Given the root of a non-empty binary tree, return true if it is complete and false otherwise.
Equivalently: in a level-order traversal that also enqueues missing children, no real node may appear after the first missing one. That check runs in O(n).
Examples
Constraints
- 1 <= number of nodes <= 100
- 1 <= Node.val <= 1000
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.