C++ || Easy || DP || Recursion + Memoization
\n// T.C. -> O(N)\n// S.C. -> O(N) [Recursion auxillary stack space] + O(N) [Unordered Map]\nclass Solution {\npublic:\n    unordered_map<TreeNode*,int> mp;\n  
```\n// T.C. -> O(N)\n// S.C. -> O(N) [Recursion auxillary stack space] + O(N) [Unordered Map]\nclass Solution {\npublic:\n    unordered_map<TreeNode*,int> mp;\n    int rob(TreeNode* root) {\n        if(root == NULL)return 0;\n        if(mp.count(root)) return mp[root];\n        int sum1 = root->val;\n        \n        if(root->left != NULL){\n          sum1 +=  rob(root->left->left);\n          sum1 += rob(root->left->right);\n        }\n        \n        if(root->right != NULL){\n            sum1 += rob(root->right->left);\n            sum1 += rob(root->right->right);\n        }\n        int sum2 = rob(root->left) + rob(root->right);\n        return mp[root] = max(sum1,sum2);\n    }\n};\n```
['Dynamic Programming', 'Memoization', 'C', 'C++']