✅✅ Beats 100% || O(n) || Easy Solution
IntuitionThe problem requires modifying an array based on certain rules:
If two adjacent elements are equal, double the first and set the second to zero.
Move a
## Intuition
The problem requires modifying an array based on certain rules:  
1. If two adjacent elements are equal, double the first and set the second to zero.  
2. Move all nonzero elements to the left while maintaining relative order.  

## Approach
- Iterate through the array once. If two adjacent elements are equal (and nonzero), double the first and set the second to zero.  
- Use a two-pointer technique to shift nonzero elements to the left efficiently.  
- The `j` pointer keeps track of where the next nonzero element should be placed.  
- If `nums[i]` is nonzero, swap it with `nums[j]` (if needed) and increment `j`.  

## Complexity Analysis
- **Time Complexity**: \(O(n)\), as we traverse the array twice in a single pass.  
- **Space Complexity**: \(O(1)\), since we modify the array in place without extra storage.  

##  Code
```cpp []
class Solution {
public:
    vector<int> applyOperations(vector<int>& nums) {
        int n = nums.size();
        int j = 0;
        for (int i = 0; i < n; i++) {
            if (i + 1 < n && nums[i] == nums[i + 1] && nums[i] != 0) {
                nums[i] *= 2;
                nums[i + 1] = 0;
            }
            if (nums[i] != 0) {
                if (i != j) swap(nums[i], nums[j]);
                j++;
            }
        }
        return nums;
    }
};
```
# Have a Good Day 😊 UpVote?
['Array', 'Two Pointers', 'Simulation', 'C++']