✅INTUITIVE| Detailed Explanation| C++ O(n) Recursion+Memo
Explanation:\n\nWe know that we cant choose consecutive nodes in a tree thus this leaves us with 2 options when we reach a node-\n1)Include that node and then i
**Explanation**:\n\nWe know that we cant choose consecutive nodes in a tree thus this leaves us with 2 options when we reach a node-\n1)**Include that node** and then include its **grandchildren** ( that are root->left->left, root->left->right and root->right->left,root->right->right) in this way we dont select any connected nodes.\n2)**Dont**  include the node and return the sum of maximum values of its **children** that are the left and right subtrees i.e. call our function on root->left and root->right\n\nNow if we write a purely recursive function for this it **will result in a TLE** as we will call the function on a node many times ( granchildren of our current node will also be the future children of the left and right subtrees) thus we use memoization.\nWe simply use an unordered map with key as TreeNode* and value as int to maintain the memo.\n\n``` \nclass Solution {\n    int max_num=INT_MIN;\npublic:\n    \n    unordered_map<TreeNode*,int>umap;\n    int helper(TreeNode*root){\n        \n        if(root==NULL)return 0;\n        if(umap[root])return umap[root];\n        int left_max=0;\n        int right_max=0;\n        if(root->left){\n            left_max=helper(root->left->left)+helper(root->left->right);\n        }\n       if(root->right){\n            right_max=helper(root->right->left)+helper(root->right->right);\n       }\n        \n        return umap[root]=max(root->val+left_max+right_max,helper(root->left)+helper(root->right));\n        \n        \n    }\n\n    \n    int rob(TreeNode* root) {\n        return helper(root);\n    }\n};\n```
['Recursion', 'Memoization', 'C']