🏆 THE MOST EASIEST TO UNDERSTAND SOLUTION | Beats 100 % 🎯  💯
IntuitionThe problem requires modifying an array based on specific operations: doubling consecutive equal elements and shifting non-zero elements to the front.
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The problem requires modifying an array based on specific operations: doubling consecutive equal elements and shifting non-zero elements to the front.  
Observing the requirements, a single pass can handle both operations efficiently.

# Approach
<!-- Describe your approach to solving the problem. -->
1. Traverse the array from left to right.
2. If two consecutive elements are equal, double the first and set the second to zero.
3. Maintain a pointer `non_zero_idx` to track the position where non-zero elements should be placed.
4. In the same pass, swap non-zero elements with `non_zero_idx` to shift them forward.

# Complexity
- Time complexity:  
  - $$O(n)$$ since we traverse the array only once.
  
- Space complexity:  
  - $$O(1)$$ as the operations are done in-place.

# Code
```cpp []
class Solution {
    public:
        vector<int> applyOperations(vector<int>& nums) {
            int n = nums.size();
            int non_zero_idx = 0; 

            for(int i = 0; i < n; i++) {
                if(i < n - 1 && nums[i] == nums[i + 1]) {
                    nums[i] *= 2;
                    nums[i + 1] = 0;
                }
                if(nums[i] != 0) {
                    swap(nums[i], nums[non_zero_idx++]);
                }
            }

            return nums;
        }
};

['C++']