You are given two integer arrays preorder and inorder where:
preorderis the preorder traversal of a binary tree (root → left → right).inorderis the inorder traversal of the same tree (left → root → right).
Return the postorder traversal (left → right → root) of the tree.
Example:Input:
preorder = [1,2,4,5,3,6]
inorder = [4,2,5,1,3,6]Output:
[4,5,2,6,3,1]
This problem revolves around reconstructing the traversal logic of a binary tree using two known traversal orders. The key insight is that preorder gives you the root first, while inorder tells you how the tree splits into left and right subtrees. Once the tree structure is conceptually divided using these properties, you can recursively determine the postorder sequence. The challenge lies in correctly identifying subtree boundaries and preserving traversal order.