Reconstruct tree postorder

Write codeMedium30 minMicrosoft style

Your task

Given preorder and inorder traversals of a binary tree with distinct values, reconstruct the tree and return its postorder traversal as a list. Both inputs describe the same tree and have equal length. 0 <= length <= 3000.

Examples

pre_in_to_post(preorder: list[int], inorder: list[int]) -> list[int]
Example 1
Inputpre_in_to_post([3, 9, 20, 15, 7], [9, 3, 15, 20, 7])
Output[9, 15, 7, 20, 3]