100% BEAT 🚀 || WITH APPROACH 😁 || BIGNNER FRIENDLY 😊 || EASY SOLN 🎯|| 2 LOOP SOLN ||💯🚀🎯🔥🔥
Approach1 ) Initialize the result array:


Create a new array result of the same length as the input array nums. This will store the final result with all non-z


# Approach
<!-- Describe your approach to solving the problem. -->
1 ) Initialize the result array:
- > Create a new array result of the same length as the input array nums. This will store the final result with all non-zero values moved to the front and zeroes moved to the end.

2 ) First Pass: Apply the merge operation:

 - > Iterate through the array nums (except the last element).
- > For each adjacent pair nums[i] and nums[i + 1], if they are equal, merge them:
- > Double the value of nums[i] (i.e., nums[i] = 2 * nums[i]).
- > Set nums[i + 1] = 0 (since it has been merged into nums[i]).

3 ) Second Pass :  Place non-zero elements into the result array:

- > Iterate through the array nums and copy all non-zero elements into the result array starting from the first position.

4 ) Fill the remaining positions with zeroes:

- > After placing all non-zero elements, fill the remaining positions in the result array with zeros.

5) Return the result:

- > The final result array now contains all merged elements at the front, followed by the zeros at the end.

# Complexity
- Time complexity : O(n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity : O(n)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    vector<int> applyOperations(vector<int>& nums) {

    int n = nums.size();
    vector<int> result(n, 0);  // Create a result vector initialized to zero.
    int index = 0;  // This will keep track of where to place non-zero elements in the result.

    // First pass: Apply the operation and merge adjacent elements.
    for (int i = 0; i < n - 1; ++i) {
        if (nums[i] == nums[i + 1]) {
            nums[i] = 2 * nums[i];  // Double the value of nums[i]
            nums[i + 1] = 0;  // Set nums[i + 1] to zero
        }
    }

    // Place non-zero elements in the result vector.
    for (int i = 0; i < n; ++i) {
        if (nums[i] != 0) {
            result[index++] = nums[i];  // Add non-zero elements to the result.
        }
    }

    // Fill the remaining spaces with zeroes.
    for (int i = index; i < n; ++i) {
        result[i] = 0;
    }

    return result;  // Return the final result array

        
    }
};
```
PLEASE UPVOTE 🤗🤗🤗🤗🤗🤗🤗🤗🤗🤗🤗🤗🤗🤗🤗🤗🤗🤗🤗🤗🤗🤗
['C++']