Recurrsively solve this problem by divding original problem into left and right child sub-problems using the first value in preorder traversal or last on in postorder traversal.