Efficient And Easy Solution 😉😉💯💯Beats
IntuitionThe problem requires modifying an array by doubling adjacent equal elements and setting the second one to zero, followed by shifting all zeroes to the


---

## **Intuition**  
The problem requires modifying an array by doubling adjacent equal elements and setting the second one to zero, followed by shifting all zeroes to the end while maintaining the order of non-zero elements. The approach is similar to the **2048 game mechanics**.

---

## **Approach**  
1. **Merging Adjacent Equal Elements:**  
   - Iterate through the array from left to right.  
   - If two adjacent elements are equal, double the first element and set the second one to zero.  

2. **Shifting Zeroes to the End:**  
   - Create a new list to store non-zero elements while iterating through the array.  
   - Append zeroes at the end to maintain the original array size.  

This approach ensures that the array is processed efficiently in two passes.

---

## **Complexity Analysis**  

- **Time Complexity:**  
  - First pass (merging): \(O(n)\)  
  - Second pass (shifting zeroes): \(O(n)\)  
  - Overall: **\(O(n)\)**  

- **Space Complexity:**  
  - Using an extra `vector<int> result` of size \(n\): **\(O(n)\)**  
  - If modifying in place, space can be reduced to **\(O(1)\)**.

---

## **Code**  
```cpp
class Solution {
public:
    vector<int> applyOperations(vector<int>& nums) {
        int n = nums.size();
        
        for (int i = 0; i < n - 1; i++) {
            if (nums[i] == nums[i + 1]) {
                nums[i] *= 2;
                nums[i + 1] = 0;
            }
        }

        vector<int> result;
        for (int num : nums) {
            if (num != 0) result.push_back(num);
        }
        while (result.size() < n) {
            result.push_back(0);
        }

        return result;
    }
};
```

This solution is **efficient** and follows a **clear logical structure**. 🚀
['C++']