Inorder Traversal of Binary Tree
You are provided with a binary tree consisting of 'N' nodes, where each node carries an integer value. Your task is to determine the in-order traversal of the given binary tree.
Example:
Input:
For the given binary tree:
1 3 8 5 2 7 -1 -1 -1 -1 -1 -1 -1
Output:
The Inorder traversal will be [5, 3, 2, 1, 7, 4, 6].
Explanation:
The input represents the level order traversal of the binary tree. Each level is denoted consecutively, and a '-1' symbolizes a null node. For example:
[
Level 1: 1
Level 2: 3 8
Level 3: 5 2 7 -1
]
Constraints:
1 <= T <= 10
0 <= N <= 3000
0 <= data <= 10^9
- Time limit: 1 second
Input:
The first line contains an integer 'T' which denotes the number of test cases.
The first line of each test case contains elements of the tree in level order. Values of nodes are separated by a single space, with -1 representing a null node.
Output:
For each test case, return a vector containing the in-order traversal as space-separated integers.
Note:
- No need to print the output, focus on implementing the function to return results.
- The input terminates when all elements at the lowest level are null (-1).
AnswerBot
1y
The task is to find the in-order traversal of a given binary tree.
Implement a recursive function to perform in-order traversal of the binary tree
Start from the left subtree, then visit the root, and f...read more
Help your peers!
Add answer anonymously...
Top Jio Software Developer interview questions & answers
Popular interview questions of Software Developer
Stay ahead in your career. Get AmbitionBox app
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
Get AmbitionBox app