Construct Binary Tree from Inorder and Postorder Traversal [C++]
IntuitionTo construct the binary tree, the key is to leverage the properties of the inorder and postorder traversal sequences.
The last element in the postorder
# Intuition
To construct the binary tree, the key is to leverage the properties of the **inorder** and **postorder** traversal sequences.  
- The last element in the postorder traversal is the root of the tree.
- Using the root's position in the inorder sequence, we can determine the left and right subtrees.

By recursively dividing the sequences, we can build the tree from the bottom up.

# Approach
1. Use a hash map to store the indices of elements in the inorder traversal for quick access.
2. Start from the last element in the postorder traversal (the root of the tree).
3. Recursively divide the inorder sequence into left and right subtrees based on the root's position.
4. Build the right subtree first (as postorder processes left subtree before right subtree).

# Complexity
- **Time complexity:**  
  $$O(n)$$  
  Each node is processed once, and lookups in the hash map take constant time.
  
- **Space complexity:**  
  $$O(n)$$  
  Space is used for the hash map and the recursion stack.

# Code
```cpp
class Solution {
public:
    TreeNode* buildTree(vector<int>& inorder, vector<int>& postorder) {
        unordered_map<int, int> inorderIndexMap;
        for (int i = 0; i < inorder.size(); ++i) {
            inorderIndexMap[inorder[i]] = i;
        }
        int postIndex = postorder.size() - 1;
        return constructTree(inorder, postorder, inorderIndexMap, postIndex, 0, inorder.size() - 1);
    }

    TreeNode* constructTree(vector<int>& inorder, vector<int>& postorder, unordered_map<int, int>& inorderIndexMap, int& postIndex, int inStart, int inEnd) {
        if (inStart > inEnd) return nullptr;

        int rootVal = postorder[postIndex--];
        TreeNode* root = new TreeNode(rootVal);
        int rootIndex = inorderIndexMap[rootVal];

        root->right = constructTree(inorder, postorder, inorderIndexMap, postIndex, rootIndex + 1, inEnd);
        root->left = constructTree(inorder, postorder, inorderIndexMap, postIndex, inStart, rootIndex - 1);

        return root;
    }
};
```
['C++']