Level Order Traversal Problem Statement

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

Input:

The first line contains an integer 'T', representing the number of test cases. For each test case, the first line contains elements of the tree in level order, with node values separated by a single space. If a node is null, it is represented by -1.

Output:

For each test case, print the level order traversal of the tree with node values separated by a single space. Each test case should be printed on a new line.

Example:

For input: 1 2 3 4 -1 5 6 -1 7 -1 -1 -1 -1 -1 -1
Output: 1 2 3 4 5 6 7

Constraints:

  • 1 <= T <= 100
  • 0 <= N <= 1000
  • 0 <= data <= 106 and data ≠ -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. Time Limit: 1sec

Note:

You are not required to print anything as it is already handled. Just implement the function and return the required results.

AnswerBot
1d

Level order traversal of a binary tree is returned for each test case.

  • Implement a function to perform level order traversal of a binary tree

  • Use a queue data structure to keep track of nodes at each le...read more

Help your peers!
Add answer anonymously...
Goldman Sachs Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

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

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter