Beginner Friendly : Easy Solution - Recursive + DP approach
\n\n# Code 1 - Recursive( WITH TLE)\n\nclass Solution:\n    def solve(self,ind,flag,n,nums):\n        if ind == n:\n            return 0\n        if flag == 0:\
\n\n# Code 1 - Recursive( WITH TLE)\n```\nclass Solution:\n    def solve(self,ind,flag,n,nums):\n        if ind == n:\n            return 0\n        if flag == 0:\n            a = nums[ind] + self.solve(ind+1,0,n,nums)\n            b = -1*nums[ind] + self.solve(ind+1,1,n,nums)\n            return max(a,b)\n        else:\n            return nums[ind] + self.solve(ind+1,0,n,nums)\n    def maximumTotalCost(self, nums: List[int]) -> int:\n        n = len(nums)\n        return nums[0] + self.solve(1,0,n,nums)\n\n\n```\n\n# Code 2 - DP\n```\nclass Solution:\n    def maximumTotalCost(self, nums: List[int]) -> int:\n        n = len(nums)\n        dp =[[None for _ in range(2)] for _ in range(n)]\n        \n        def solve(ind,flag):\n            if ind == n:\n                return 0\n            if dp[ind][flag] is not None:\n                return dp[ind][flag]\n            if flag == 0:\n                a = nums[ind] + solve(ind+1, 0)\n                b = -1*nums[ind] + solve(ind+1,1)\n                dp[ind][flag] = max(a,b)\n            else:\n                dp[ind][flag] = nums[ind] + solve(ind+1,0)\n            return dp[ind][flag]\n            \n        \n        return nums[0] + solve(1, 0)\n\n\n```\n\n
['Python3']