🔥Clean DP Code✅ || ⚡Memoization
\n\n# Complexity\n\n- Time complexity:\nO(n * 2)\n\n- Space complexity:\nO(n * 2)\n\n\n# Code\n## Please Upvote if it helps\uD83E\uDD17\n\nclass Solution {\npub
\n\n# Complexity\n```\n- Time complexity:\nO(n * 2)\n\n- Space complexity:\nO(n * 2)\n```\n\n# Code\n## Please Upvote if it helps\uD83E\uDD17\n```\nclass Solution {\npublic:\n    long dp[100001][2];\n    long helper(int ind, int n, vector<int>& nums, bool ch){\n        if(ind == n)\n            return 0;\n        if(dp[ind][ch] != -1)\n            return dp[ind][ch];\n        long maxi = LONG_MIN;\n        maxi = ((!ch) ? nums[ind] : -1 * nums[ind]) + helper(ind + 1, n, nums, !ch);\n        maxi = max(maxi, nums[ind] + helper(ind + 1, n, nums, true));\n        return dp[ind][ch] = maxi;\n    }\n    \n    long long maximumTotalCost(vector<int>& nums) {\n        int n = nums.size();\n        memset(dp, -1, sizeof(dp));\n        return helper(0, n, nums, false);\n    }\n};\n```
['Dynamic Programming', 'Memoization', 'C++']