java - intutive - for beginners
Code


# Code
```java []
import java.util.*;

class Solution {
    public int minimumPairRemoval(int[] nums) {
        boolean sorted = true;
        for(int i=0; i<nums.length-1; i++) {
            if(nums[i] > nums[i+1]) {
                sorted = false;
                break;
            }
        }

        if(sorted) return 0;

        List<Integer> list = new ArrayList<>();   
             

        for(int num: nums) list.add(num);

        int cnt = 0;

        boolean inc = false;




        while(!inc) {
            cnt++;
            
            int min = Integer.MAX_VALUE;
            int idx = -1;
            for(int i=0; i<list.size()-1; i++) {
                int ps = list.get(i) + list.get(i+1);
                
                if(ps < min) {
                    min = ps;
                    idx = i;
                }
            }

            list.remove(idx);
            list.add(idx, min);
            list.remove(idx+1);



            sorted = true;
            for(int i=0; i<list.size()-1; i++) {
                if(list.get(i) > list.get(i+1)) {
                    sorted = false;
                    break;
                }
            }
            if(sorted) inc = true;

        }



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