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.
AnswerBot
4mo

The task is to determine the in-order traversal of a Binary Tree given in level order.

  • Implement a function to perform in-order traversal of a Binary Tree

  • Use recursion to traverse left subtree, visit r...read more

Help your peers!
Select
Add answer anonymously...

Visa Software Engineer interview questions & answers

A Software Engineer was asked 8mo agoQ. Explain the React lifecycle methods and how they work.
A Software Engineer was asked Q. Given an array of integers, rearrange the array such that all even numbers appea...read more
A Software Engineer was asked Q. How do you calculate the time taken by the kth person to collect n number of tic...read more

Popular interview questions of Software Engineer

A Software Engineer was asked 8mo agoQ1. Explain the React lifecycle methods and how they work.
A Software Engineer was asked Q2. How do you calculate the time taken by the kth person to collect n number of tic...read more
A Software Engineer was asked Q3. Given an array of integers, rearrange the array such that all even numbers appea...read more
Visa Software Engineer 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