Loading...
Loading...
Loading...
A tree with different values was written down twice: once in preorder and once in inorder. Rebuild the tree and print its postorder list, separated by spaces.
Example 1
Input
3 9 20 15 7 9 3 15 20 7
Output
9 15 7 20 3
Prints 9 15 7 20 3.
Example 2
Input
1 1
Output
1
Try the problem first. Open one hint at a time.
The first preorder value is the root.
Find it in the inorder list: the values before it are the left side.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor