Java | Recursive | Most Intutive | Intution Explanation Using Image
Intution: Firstly observe both the arrays and think how they are formed from a tree...which index contain which part from the tree.\n * Inorder Traversal: After
**Intution:** Firstly observe both the arrays and think how they are formed from a tree...which index contain which part from the tree.\n * *Inorder Traversal*: After storing the inorder traversal of tree u can see that root will always come in between and left of root will be all the nodes of left subtree and in right will be nodes of right subtree.\n* *Postorder Traversal*: Here u can see that in the array firstly there will be all the left subtree nodes then all the righgt subtree nodes and then at last will be root;\n     ##### So now u can say that you have the root node confirmed that is at last index of postorder traversal array\n\t Now u have to just recursively update the left and right subtree of the root using your two arrays.\n\t \n\t ![image](https://assets.leetcode.com/users/images/558dd002-738b-4189-8691-97c6d2de39c2_1637464626.6180944.jpeg)\n\n\n```\nclass Solution {\n    public TreeNode buildTree(int[] inorder, int[] postorder) {\n        return build(inorder,0,inorder.length-1,postorder,0,postorder.length-1);\n    }\n    \n    public TreeNode build(int[] inorder, int inS, int inE, int[] postorder, int posS, int posE){\n        if(inS>inE || posS>posE) return  null;\n        \n        TreeNode root = new TreeNode(postorder[posE]);\n        \n        int rootI=0;\n        for(int i=0;i<inorder.length;i++){\n            if(inorder[i]==root.val){\n                rootI = i;\n                break;\n            }\n        }\n        \n        root.left = build(inorder,inS,rootI-1,postorder,posS,posS+rootI-inS-1);\n        root.right = build(inorder,rootI+1,inE,postorder,posS+rootI-inS,posE-1);\n        \n        return root;\n    }\n}
['Recursion', 'Java']