✅💥BEATS 100%✅💥 || 🔥EASY CODE🔥 || ✅💥EASY EXPLAINATION✅💥 || JAVA || C++ || PYTHON
IntuitionThe problem asks us to apply some operations on an array of integers. The goal is to iterate through the array and, whenever two adjacent elements are
# Intuition
The problem asks us to apply some operations on an array of integers. The goal is to iterate through the array and, whenever two adjacent elements are the same, combine them by multiplying the first element by 2 and setting the second one to 0. After that, we need to shift the non-zero elements to the left side of the array and set all remaining elements to 0. The solution should be done in-place without using extra space for a second array.

# Approach
We can break the solution into two main steps:
1. **Merge adjacent equal elements**: We iterate through the array, and whenever we find two adjacent elements that are the same, we double the first element and set the second element to 0.
   
2. **Shift the non-zero elements to the left**: Once we’ve handled the merging step, we need to shift all non-zero elements to the left side of the array and fill the remaining positions with 0s.

- The first loop ensures that adjacent elements that are the same are combined.
- The second loop is responsible for shifting all non-zero values to the left side of the array.
- The third loop fills the remaining positions with zeros.

# Complexity
- **Time complexity**: $$O(n)$$  
  We are iterating through the array a constant number of times (twice in total), so the overall time complexity is linear.

- **Space complexity**: $$O(1)$$  
  The solution modifies the array in place without using any extra space.

# Code
``` Java []
class Solution {
    public int[] applyOperations(int[] nums) {
        // Step 1: Merge adjacent equal elements
        for(int i = 0; i < nums.length - 1; i++) {
            if(nums[i] == nums[i + 1]) {
                nums[i] = nums[i] * 2;  // Combine the elements
                nums[i + 1] = 0;         // Set the second element to 0
            }
        }

        // Step 2: Shift non-zero elements to the left
        int j = 0;
        for(int i = 0; i < nums.length; i++) {
            if(nums[i] != 0) {
                nums[j] = nums[i];  // Move non-zero elements to the left
                j++;
            }
        }

        // Step 3: Fill the remaining positions with zeros
        while(j < nums.length) {
            nums[j] = 0;
            j++;
        }

        return nums;
    }
}
```
``` C++ []
class Solution {
public:
    vector<int> applyOperations(vector<int>& nums) {
        // Step 1: Merge adjacent equal elements
        for (int i = 0; i < nums.size() - 1; i++) {
            if (nums[i] == nums[i + 1]) {
                nums[i] = nums[i] * 2;  // Combine the elements
                nums[i + 1] = 0;         // Set the second element to 0
            }
        }

        // Step 2: Shift non-zero elements to the left
        int j = 0;
        for (int i = 0; i < nums.size(); i++) {
            if (nums[i] != 0) {
                nums[j] = nums[i];  // Move non-zero elements to the left
                j++;
            }
        }

        // Step 3: Fill the remaining positions with zeros
        while (j < nums.size()) {
            nums[j] = 0;
            j++;
        }

        return nums;
    }
};

```
``` Python []
class Solution:
    def applyOperations(self, nums):
        # Step 1: Merge adjacent equal elements
        for i in range(len(nums) - 1):
            if nums[i] == nums[i + 1]:
                nums[i] = nums[i] * 2  # Combine the elements
                nums[i + 1] = 0        # Set the second element to 0

        # Step 2: Shift non-zero elements to the left
        j = 0
        for i in range(len(nums)):
            if nums[i] != 0:
                nums[j] = nums[i]  # Move non-zero elements to the left
                j += 1

        # Step 3: Fill the remaining positions with zeros
        while j < len(nums):
            nums[j] = 0
            j += 1

        return nums

```
['Array', 'Math', 'Two Pointers', 'Simulation', 'Python', 'C++', 'Java']