
Asked in Juniper Networks
Level Order Traversal of Binary Tree
Given a Binary Tree of integers, your task is to return the level order traversal of the tree.
Input:
The first line contains an integer 'T' which denotes the number of test cases. For each test case, the first line contains elements of the tree in the level order form. The elements are space-separated values of the nodes, where '-1' represents a null node.
Output:
For each test case, output the nodes in level order traversal separated by a single space, with each test case output 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:
Level 1:
The root node is 1
Level 2:
Left child of 1 is 2
Right child of 1 is 3
Level 3:
Left child of 2 is 4
Right child of 2 is null (-1)
Left child of 3 is 5
Right child of 3 is 6
Level 4:
Left child of 4 is null (-1)
Right child of 4 is 7
All children of 5 and 6 are null (-1)
Constraints:
1 <= T <= 100
0 <= N <= 1000
0 <= data <= 106
anddata != -1
Where ‘T’ is the number of test cases, ‘N’ is the total number of nodes in the binary tree, and ‘data’ is the value of the binary tree node.

AnswerBot
4mo
Return the level order traversal of a Binary Tree of integers.
Perform a level order traversal using a queue data structure
Start by pushing the root node into the queue
Pop each node from the queue, pri...read more
Help your peers!
Add answer anonymously...
Top Staff Engineer Interview Questions Asked at Juniper Networks
Q. Implement a telephone directory program.
Q. Implement a dictionary.
Q. Explain the TCP packet header, the meaning of each field, and the usage of each ...read more
Interview Questions Asked to Staff Engineer at Other Companies
Top Skill-Based Questions for Juniper Networks Staff Engineer
Networking Interview Questions and Answers
250 Questions
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
System Design Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


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
AmbitionBox Awards
Get AmbitionBox app

