Python Simple Solution O(n) Time and O(1) Space
We iterate over nums from left to right and greedily choose elements which satisfy the given condition in our final array. While iterating, we need to keep a co
We iterate over nums from left to right and **greedily choose elements** which satisfy the given condition in our final array. While iterating, we need to **keep a count** of how many elements we have chosen so far to make greedy choices.\n\n### Idea:\n1. Iterate from left to right uptil second last element:\n    1.1 If `count` is even and current element is same as next one, we delete it.\n    1.2 Otherise we take that element and increase `count`.\n2. Take the last element as it is and increment `count`.\n3. If our final `count` is odd, delete the last element as well.\n\n**Time Complexity:** *O(n)*\n**Space Complexity:** *O(1)*\n\n```\nclass Solution:\n    def minDeletion(self, nums: List[int]) -> int:\n        n = len(nums)\n        dels = cnt = 0\n\n        for i in range(n - 1):\n            if (cnt % 2) == 0 and (nums[i] == nums[i + 1]):\n                dels += 1\n            else:\n                cnt += 1\n                \n        cnt += 1         # Take the last element as it is.\n        dels += cnt & 1  # If final count is odd, delete last element.\n        return dels\n```\n\n***Do upvote if you like the solution. Have a nice day!***\n\n\n
['Greedy', 'Python', 'Python3']