🚀0ms Runtime || Beats 100% || O(1) space || best optimal approach
Intuition
A "beautiful array" is defined as one where every even-indexed element is different from the next element.
We iterate through the array, removing dupl
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
- A "beautiful array" is defined as one where every even-indexed element is different from the **next element**.
- We iterate through the array, removing duplicate elements that would violate this condition at even indices.


# Approach
<!-- Describe your approach to solving the problem. -->
- ✅ Step 1: Use a counter ctr to track the number of deletions.
- ✅ Step 2: Iterate through the array and check if nums[i] == nums[i+1] at even indices.
- ✅ Step 3: If yes, increment ctr (delete nums[i]).
- ✅ Step 4: If the final array has an odd length, delete one more element to maintain even length.
# Complexity
Time Complexity: $$O(n)$$ → Single pass through the array.
Space Complexity: $$O(1)$$→ No extra memory used.

![Screenshot 2025-03-16 201553.png](https://assets.leetcode.com/users/images/bc35b9ea-e8fd-44d4-87fa-16c73ac16523_1742136552.551632.png)

# Code
```cpp []
class Solution {
public:
    int minDeletion(vector<int>& nums) {
        int ctr= 0,i=0;
        while(i<nums.size()-1){
            if((i-ctr)%2==0 || i==0){
                if(nums[i]==nums[i+1]){
                    ctr++;
                }
            }
             i++;
        }
        if((nums.size()-ctr)%2==0) return ctr;
        return ctr+1;
    }
};
```
['Array', 'Stack', 'Greedy', 'C++', 'Java', 'Python3']