Sorted Order Printing of a BST Array

Given a Binary Tree consisting of 'N' nodes with integer values, your task is to determine the in-order traversal of the Binary Tree.

Input:

The first line contains an integer 'T', indicating the number of test cases.
Each test case consists of a single line containing the elements of the tree in level order. The line includes values of nodes separated by a single space. If a node is null, it is denoted by -1.

Output:

For each test case, output a vector containing the In-Order traversal values of the given Binary Tree. Each test case's output should be a line of 'N' space-separated integers representing the node values in In-Order traversal.

Example:

Input:
2
1 3 8 5 2 7 -1 -1 -1 -1 -1 -1 -1
10 4 6 -1 -1 5 8
Output:
[5, 3, 2, 1, 7, 4, 6]
[4, 10, 5, 6, 8]
Explanation:

Example 1 depicts the tree where Node 1 is the root. The traversal follows In-Order (Left, Root, Right), resulting in [5, 3, 2, 1, 7, 4, 6].

Constraints:

  • 1 <= T <= 10
  • 0 <= N <= 3000
  • 0 <= data <= 10^9 (where 'data' denotes the node value of the binary tree nodes)
Note:
You don't need to print anything, it has already been taken care of. Implement the function provided.
Be the first one to answer
Add answer anonymously...
Visa Software Engineer 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
Profile Image
Hello, Guest
Awards 2025
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
Stay ahead in your career with AmbitionBox app