BETA

#### Submissions: 4368 Accuracy: 34.82%

Tree from Postorder and Inorder (Function Problem)

Given inorder and postorder traversals of a Binary Tree, construct the tree

For example, if given inorder and postorder traversals are {4, 8, 2, 5, 1, 6, 3, 7} and {8, 4, 5, 2, 6, 7, 3, 1}  respectively, then your function should construct below tree.

1
/      \
2        3
/    \     /   \
4     5   6    7
\
8

Input:
The task is to complete the method which takes three arguments, one is an array that has inorder traversal, second is another array that has postorder traversal, third is size of two arrays (You may assume that both arrays are of same size).

There are multiple test cases. For each test case, this method will be called individually.

Output:
The function should return root of constructed tree.

Constraints:
1 <=T<= 30
1 <= Size of arrays <= 100
1 <= Values in arrays <= 1000

Example:
Input:

1
8
4 8 2 5 1 6 3 7
8 4 5 2 6 7 3 1

Output:
1 2 4 8 5 3 6 7

There is one test case.  The first line of input is number of elements in tree. Second and third lines are inorder and postorder traversals respectively.  Output is Preorder traversal.

Note:The Input/Ouput format and Example given above are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console, and should not print anything on stdout/console. The task is to complete the function specified, and not to write the full code.

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

Contributor: Amit Khandelwal

##### It is recommended to 'Compile & Test' your code before clicking 'Submit'!

Compilation/Execution Result:

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