Construct tree from Inorder and LevelOrder
Submissions: 2595   Accuracy:

43.92%

  Difficulty: Medium   Marks: 4

Given inorder and level-order traversals of a Binary Tree, construct the Binary Tree and return the root Node. 

Input:
First line consists of T test cases. First line of every test case consists of N, denoting number of elements is respective arrays. Second and third line consists of arrays containing Inorder and Level-order traversal respectively.

Output:
Single line output, print the preOrder traversal of array.

Constraints:
1<=T<=100
1<=N<=100

Example:
Input:

2
3
1 0 2 
0 1 2 
7
3 1 4 0 5 2 6 
0 1 2 3 4 5 6 
Output:
0 1 2
0 1 3 4 2 5 6

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Saksham Raj Seth
Author: saksham seth


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.