Easy Python solution. O(n) time, O(1) space
Intuition\nThere is no reason to split it up into groups larger than 2 because it is alternating. We can either choose to keep the number, or flip the number (a
# Intuition\nThere is no reason to split it up into groups larger than 2 because it is alternating. We can either choose to keep the number, or flip the number (and not have flipped the one before it).\n\n# Approach\nIf we don\'t flip it, then we can just add it to the max of our 2 previous scenarios. If we do flip it, we have to take the last scenario where we didn\'t flip it. Also note we cannot flip the first number.\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n# Code\n```\nclass Solution:\n    def maximumTotalCost(self, nums: List[int]) -> int:\n        n = len(nums)\n        a = nums[0] #didnt flip last\n        b = nums[0] #flipped last\n        for i in range(1,n):\n            a,b = nums[i]+max(a,b),a-nums[i]\n        return max(a,b)\n```
['Python3']