Why so complicated answers are so highly voted?
1 USE A GLOBAL INDEX AND START FROM RIGHT TILL LEFT\n2 AT THE START, CREATE ROOT, AND SET RIGHT AND LEFT\n3 RETURN NULL IF (start>end)\n4 FIND INDEX IF ROOT.VAL
1 USE A GLOBAL INDEX AND START FROM RIGHT TILL LEFT\n2 AT THE START, CREATE ROOT, AND SET RIGHT AND LEFT\n3 RETURN NULL IF (start>end)\n4 FIND INDEX IF ROOT.VAL IN INORDER AND (start, curr-1) FOR LEFT AND\n(curr+1, end)  FOR RIGHT.\n\n```\nint postIndex;\n    public TreeNode buildTree(int[] inorder, int[] postorder) {\n        int n = postorder.length;\n        if(n==0) return null;\n        if(n==1) return new TreeNode(postorder[0]);\n        postIndex = n-1;\n        return helper(inorder, postorder, 0, n-1);\n    }\n    \n    TreeNode helper(int[] inorder, int[] postorder, int start, int end){\n        if(start > end) return null;\n        \n        TreeNode root = new TreeNode(postorder[postIndex--]);\n        int curr = findIndex(inorder, root.val);\n        \n        root.right = helper(inorder, postorder, curr+1, end);\n        root.left = helper(inorder, postorder, start, curr-1);\n        return root;\n    }\n    \n    int findIndex(int[] inorder, int key){\n        for(int i = inorder.length-1; i>=0; i--){\n            if(inorder[i] == key) return i;\n        }\n        return -1;\n    }\n```\t\n\nTHE CODE FOR PREORDER IS EXACTLY THE SAME BUT WE MOVE FROM LEFT TO RIGHT\nAND SET LEFT AND THEN THE RIGHT CHILD.\n```\nint preIndex = 0;\n    public TreeNode buildTree(int[] preorder, int[] inorder) {\n        int n = preorder.length;\n        if(n==0) return null;\n        if(n==1) return new TreeNode(preorder[0]);\n        \n        return helper(preorder, inorder, 0, n-1);\n    }\n    \n    TreeNode helper(int[] preorder, int[] inorder, int start, int end){\n        if(start > end) return null;\n        \n        TreeNode root = new TreeNode(preorder[preIndex++]);\n        int curr = findIndex(inorder, root.val);\n        \n        root.left = helper(preorder, inorder, start, curr-1);\n        root.right = helper(preorder, inorder, curr+1, end);\n        return root;\n    }\n    \n    int findIndex(int[] inorder, int key){\n        for(int i =0; i<inorder.length; i++){\n            if(inorder[i] == key) return i;\n        }\n        return -1;\n    }\n\t
['Java']