✅ C++ | Step by step Recusion --> memoization | Easy to undestand
There are two case possible :\n1. * You can pick the current root\n\t\tif you pick the current root you cannot pick its immediate children.\n\t\t so you will fi
There are two case possible :\n1. * **You can pick the current root**\n\t\t*if you pick the current root you cannot pick its immediate children.\n\t\t* so you will find if we can pick grand children if exists i.e. \n\t\t\t* root->left->left, \n\t\t\t* root->left->right, \n\t\t\t* root->right->left,\n\t\t\t* root->right-.right\n2. * **if you dont pick the current root**\n\t\t* you can pick its children i.e \n\t\t\t* root->left,\n\t\t\t* root->right\n3. **determine from which path you are getting maximum**\n\n***Recusive Approach : -***\n```\n    int rob(TreeNode* root) {\n        \n        if(!root) return 0;\n        \n        int include = root->val;\n        if(root->left) include += rob(root->left->left) + rob(root->left->right);\n        if(root->right) include += rob(root->right->left) + rob(root->right->right);\n        \n        int exclude = rob(root->left) + rob(root->right);\n        \n        return max(include, exclude);\n        \n        \n    }\n```\n\n***Memoization : -***\n```\nunordered_map<TreeNode*, int> dp;\n    int rob(TreeNode* root) {\n        \n        if(!root) return 0;\n        \n        if(dp[root]) return dp[root];\n        \n        int include = root->val;\n        if(root->left) include += rob(root->left->left) + rob(root->left->right);\n        if(root->right) include += rob(root->right->left) + rob(root->right->right);\n        \n        int exclude = rob(root->left) + rob(root->right);\n        \n        return dp[root] = max(include, exclude);\n    \n    }\n```\n\n**Make sure to give it a upvote if you find it helpful\n<Happy Coding/>**
['Dynamic Programming', 'Recursion']