Java/C++ | O(N) time O(1) space
JAVA\n\nclass Solution {\n\n    public int minDeletion(int[] nums) {\n        boolean even = true;\n        int size = 0, c = 0;\n        for (int i = 0; i < nu
**JAVA**\n```\nclass Solution {\n\n    public int minDeletion(int[] nums) {\n        boolean even = true;\n        int size = 0, c = 0;\n        for (int i = 0; i < nums.length; i++) {\n\t\t\t//current index is even and i+1 is same \n            while (i + 1 < nums.length && even && nums[i] == nums[i + 1]) {\n                i++;\n                c++;\n            }\n\t\t\t//change index parity\n\t\t\teven = !even;\n            size++;\n        }\n        return c + size % 2; // as even number of elements needed\n    }\n}\n```\n**CPP**\n```\nclass Solution {\n    public:\n        int minDeletion(vector < int > & nums) {\n            bool even = true;\n            int size = 0, c = 0;\n            for (int i = 0; i < nums.size(); i++) {\n                while (i + 1 < nums.size() && even && nums[i] == nums[i + 1]) i++, c++;\n                size++;\n                even = !even;\n            }\n            return c + size % 2;\n        }\n};\n```
[]