Easy Video Solution 🔥 || How to 🤔 in Interview || Dynamic programming || Memoization 🔥
If you like the solution Please Upvote and subscribe to my youtube channel\n\n# Easy Video Explanation\n\nhttps://youtu.be/ZzOdbGx3KAs\n\n# Code\n\nclass Soluti
***If you like the solution Please Upvote and subscribe to my youtube channel***\n\n# ***Easy Video Explanation***\n\nhttps://youtu.be/ZzOdbGx3KAs\n\n# Code\n```\nclass Solution {\npublic:\n    long long solve(int i,int f,int n,vector<int>&v,vector<vector<long long>>&dp) {\n        if(i==n)\n            return 0;\n        if(dp[i][f]!=-1)\n            return dp[i][f];\n        long long a=0,b=0;\n        if(f==0) {\n            a=v[i]+solve(i+1,0,n,v,dp);\n            b=-1*v[i]+solve(i+1,1,n,v,dp);\n        } else {\n            a=v[i]+solve(i+1,0,n,v,dp);\n            return dp[i][f]=a;\n        }\n        return dp[i][f]=max(a,b);\n    }\n    long long maximumTotalCost(vector<int>& v) {\n        int n = v.size();\n        vector<vector<long long>>dp(n,vector<long long>(2,-1));\n        long long ans = v[0]+solve(1,0,n,v,dp);\n        return ans;\n    }\n};\n```
['Dynamic Programming', 'Memoization', 'C++']