Java
Code


# Code
```java []
class Solution {
    public int minimumPairRemoval(int[] nums) {
       ArrayList<Integer> list = new ArrayList<>();
		int count = 0;
		int sum = 0;
		int min = Integer.MAX_VALUE;
		int countm=0;
		// checking if already sorted
		for (int i = 0; i <= nums.length - 1; i++) {
			list.add(nums[i]);
			if(i==nums.length-1)
			{
				break;
			}
			if (nums[i] <= nums[i + 1]) {
			
			} else {
				
			
				count++;
			}
			
		}
		
		int one = 0;
		int two = 0;
		if (count == 0) {
			// already sorted
			countm=0;
		} else {
			while (true) {
				// finding the minimum sum and removing
			countm++;
			sum=0;
			min = Integer.MAX_VALUE;
		
				for (int i = 0; i <= list.size() - 1; i++) {
					if (i == list.size() - 1) {
						break;
					}
					sum = sum + (list.get(i) + list.get(i + 1));
					if (sum < min) {
						min = sum;
						one = i;
						two = i + 1;
					}
					sum = 0;
				}
				// rempving min sum pair and adding their sum to list again
				//System.out.println("min sum pair is" + one + " " + two);
				int sum1 = list.get(one) + list.get(two);
				
				list.remove(two);
				list.remove(one);
				list.add(one, sum1);
			//	System.out.print(list);
				//checking if its non Decreasing
				count=0;
				for (int i = 0; i<=list.size()-1; i++) {
					
					if(i==list.size()-1)
					{
						break;
					}
					if(list.get(i)<=list.get(i+1))
					{
						
					}
					else {
						count++;
					}
				}
				if(count==0)
				{
					break;
				}

			}

		}
        return countm;
    }
}
```
['Java']