Inclusion Exclusion Principle | DP | Java | O(N)
Approach\n Describe your approach to solving the problem. \n1. Use Inclusion Exclusion principle which is one of form of Dynamic Programming\n\n# Video Tutorial
# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Use Inclusion Exclusion principle which is one of form of Dynamic Programming\n\n# Video Tutorial\n[Video Link\n](https://www.youtube.com/watch?v=Zvq458gwpwY)\n# Complexity\n- Time complexity: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public long maximumTotalCost(int[] nums) {\n        long flip = nums[0], noFlip = nums[0];\n        long tempFlip , tempNoFlip;\n        for (int i=1; i<nums.length; ++i) {\n            tempFlip = -nums[i] + noFlip;\n            tempNoFlip = nums[i] + Math.max(noFlip, flip);\n            noFlip = tempNoFlip;\n            flip = tempFlip;\n        }\n        return Math.max(flip, noFlip);\n    }\n}\n```
['Java']