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.
Be the first one to answer
Add answer anonymously...
Top Media.net Software Services (India) Software Developer interview questions & answers
Popular interview questions of Software Developer
>
Media.net Software Services (India) Software Developer Interview Questions
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