Adobe Logo

Asked in Adobe

Level Order Traversal of Binary Tree

Given a binary tree of integers, return its level order traversal.

Input:

The first line contains an integer 'T' which represents the number of test cases. For each test case, provide the elements of the tree in level order, separated by a single space. Use -1 to represent null nodes.

Output:

For each test case, print the nodes in level order traversal, separated by spaces, on a new line.

Example:

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

Explanation:

The input corresponds to the binary tree depicted in the provided image. The level order traversal starts from the root node and visits nodes level by level.

Constraints:

  • 1 <= T <= 100
  • 0 <= N <= 1000
  • 0 <= data <= 106 and data != -1
  • Where 'T' is the number of test cases, 'N' is the number of nodes, and 'data' is the node's value.

Note: The sequence is single-line input for each test case, and you do not need to print anything explicitly.

AnswerBot
4mo

Level Order Traversal of Binary Tree returns nodes in level order traversal.

  • Perform a level order traversal of the binary tree starting from the root node.

  • Visit nodes level by level, printing them in ...read more

Help your peers!
Select
Add answer anonymously...

Top Mts1 Interview Questions Asked at Adobe

Q. Left View of a Binary Tree Problem Statement Given a binary tree, your task is t...read more
Q. Design a system that can store an incoming stream of characters in a sorted mann...read more
Q. Top View of Binary Tree Problem Statement Given a binary tree, your task is to p...read more
Mts1 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