Construct Binary Tree from Inorder and Postorder Traversal
Given two lists representing the inorder and postorder traversal of a binary tree of integer type with 'N' nodes, construct the binary tree and return its root.
The binary tree contains only unique elements.
Input:
First line contains integer 'T', number of test cases.
For each test case:
- First line contains integer 'N', number of nodes.
- Second line contains 'N' space-separated integers, representing the Postorder traversal.
- Third line contains 'N' space-separated integers, representing the Inorder traversal.
Output:
For each test case, print the level order traversal of the constructed binary tree on a new line.
Example:
IN_ORDER = [9, 3, 15, 20, 7]
POST_ORDER = [9, 15, 7, 20, 3]
The resulting binary tree from the traversals is:
Constraints:
- 1 <= T <= 10
- 1 <= N <= 10000
- 1 <= POST_ORDER[i], IN_ORDER[i] <= 100000
Note:
You do not need to print anything; focus on implementing the function.

AnswerBot
4mo
Construct a binary tree from inorder and postorder traversal lists and return its root.
Create a map to store the indices of elements in the inorder traversal list for quick access during tree construc...read more
Help your peers!
Add answer anonymously...
Media.net Software Services (India) Software Developer interview questions & answers
A Software Developer was asked Q. Given a sequence of positive numbers, make it a non-decreasing sequence. Operati...read more
A Software Developer was asked Q. Interleaving Two Strings Problem Statement You are given three strings 'A', 'B',...read more
A Software Developer was asked Q. Boxes of Power Problem Statement Given a set of boxes represented by an array ga...read more
Popular interview questions of Software Developer
A Software Developer was asked Q1. Given a sequence of positive numbers, make it a non-decreasing sequence. Operati...read more
A Software Developer was asked Q2. Interleaving Two Strings Problem Statement You are given three strings 'A', 'B',...read more
A Software Developer was asked Q3. Boxes of Power Problem Statement Given a set of boxes represented by an array ga...read more
>
Media.net Software Services (India) Software Developer Interview 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

