Beats 100% | C++| Easy 
Intuition
The problem requires transforming an array into a non-decreasing one.
The only allowed operation is to merge adjacent elements by replacing them with
# Intuition
- The problem requires transforming an array into a non-decreasing one.
- The only allowed operation is to merge adjacent elements by replacing them with their sum.
- To minimize operations, we remove the leftmost adjacent pair with the smallest sum in each iteration.
- The idea is to cause minimal distortion to the overall ordering while steadily fixing violations.

# Approach
1. Repeatedly check if the array is non-decreasing using a helper function.
2. If not, find the leftmost adjacent pair whose sum is the smallest.
3. Remove the first element of the pair and replace the second with the sum.
4. Count each such operation.
5. Continue this process until the array becomes non-decreasing.

# Complexity
- Time complexity:
Worst-case: O(n^2), where n is the number of elements in the array.
In each operation, we do an O(n) scan and a possible O(n) erase.

- Space complexity:
O(1) extra space (ignoring the input array), since we modify in place.

# Code
```cpp
class Solution {
public:
    bool isNonDecreasing(vector<int>& nums) {
        for (int i = 1; i < nums.size(); i++) {
            if (nums[i] < nums[i - 1]) return false;
        }
        return true;
    }

    int minimumPairRemoval(vector<int>& nums) {
        int ops = 0;

        // Keep doing operations until the array is non-decreasing
        while (!isNonDecreasing(nums)) {
            int minSum = INT_MAX;
            int minIdx = -1;

            // Find the leftmost adjacent pair with the smallest sum
            for (int i = 0; i < nums.size() - 1; i++) {
                int sum = nums[i] + nums[i + 1];
                if (sum < minSum) {
                    minSum = sum;
                    minIdx = i;
                }
            }

            // Replace the pair with their sum
            nums.erase(nums.begin() + minIdx);  // Remove first of the pair
            nums[minIdx] = minSum;    // Replace second with the sum

            ops++;  // Count the operation
        }

        return ops;
    }
};

['C++']