A different Brute-force method in Java with less runtime.
IntuitionWe have to find the minimum number of operations needed to make the array non-decreasing.Operation:
Select the adjacent pair with the minimum sum in nu
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
We have to find the minimum number of operations needed to make the array non-decreasing.

**Operation:**

- Select the adjacent pair with the minimum sum in nums. If multiple such pairs exist, choose the leftmost one.
- Replace the pair with their sum.


# Approach
<!-- Describe your approach to solving the problem. -->
***My approach:***
We have to check if the array is non decreasing by checking each element if there is an element in the array which is greater than its next element then we stop and apply operarion and In the operation we find minimum sum and replace the pair with minimum sum and in place of replacing two elements sum as one element we assign sum to first value of the pair and will shift all the remaing elements in the array to left by 1 step. we decrement n by 1 as last element is already shifted. we will again start for checking the array if it is non decreasing and continue the loop until the array is non decreasing. I took count variable to calculate no of times operation is done.


# Code
```java []
class Solution {
    public void operation(int[] nums,int n){
        int min_index=0;
        int minsum=nums[0]+nums[1];
        for(int i=0;i<n-1;i++){
            if(nums[i]+nums[i+1]<minsum){
                min_index=i;
                minsum=nums[i]+nums[i+1];
            }
        }
        nums[min_index]=minsum;
        for(int i=min_index+1; i<n-1;i++){
            nums[i]=nums[i+1];
        }
        
    }
    public int minimumPairRemoval(int[] nums) {
        int n=nums.length;
        int[] pairsum=new int[n-1];
        int count=0;
        for(int i=0; i<n-1;i++){
            if(nums[i]>nums[i+1]){
                count++;
                operation(nums,n);
                i=-1;
                n--;
            }
        }
        return count;
    }
}
```
['Array', 'Java']