Problem Statement: Check Whether Binary Tree Is Complete

You are provided with a binary tree. Your task is to determine if the given binary tree is a Complete Binary Tree.

A Complete Binary Tree is defined as a binary tree in which every level, except possibly the last, is entirely filled, and all nodes in the final level are positioned to the left.

Input:

The input begins with an integer T, indicating the number of test cases. For each test case, a sequence of node values is given in level order traversal, where the values are separated by spaces. If a node is null, it is represented by -1.

1
2 3
4 -1 5 6
-1 7 -1 -1 -1 -1
-1 -1

Output:

For each test case, output 1 if the Binary Tree is complete, and 0 if it is not. Continuous lines indicate individual test case outputs.

Example:

Input:
1 2 3 4 -1 5 6 -1 7 -1 -1 -1 -1 -1 -1
Output:
1

Constraints:

  • 1 ≤ T ≤ 100
  • 1 ≤ N ≤ 3000, where N is the total number of nodes in the binary tree.
  • 1 ≤ data ≤ 105 and data ≠ -1
Note:

No need to print anything for solving the problem; the implementation should return the results directly.

AnswerBot
1y

The task is to check whether a given binary tree is a complete binary tree or not.

  • A complete binary tree is a binary tree where every level, except possibly the last, is completely filled.

  • All nodes in...read more

Help your peers!
Select
Add answer anonymously...

Top Software Developer Interview Questions Asked at Jio

Q. How do you optimize React applications?
Q. Use any public API to fetch data and display it as a list on the screen.
Q. Count the frequency of letters in a sentence with a method having least time com...read more
Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits