Java || Brute force
Intuition
Simulate the entire process.
Approach
initialize the count variable to 0.
traverse the array to find the array with minSum.
let pair be [index1, index
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
1. Simulate the entire process.
# Approach
<!-- Describe your approach to solving the problem. -->
1. initialize the count variable to 0.
2. traverse the array to find the array with minSum.
3. let pair be `[index1, index2]`. put minSum at index1 and remove element at index2. and increment the count.
4. continue this until array is sorted or only one element is remaining in the array.
5. return count.
# Complexity
- Time complexity:$$O(n) + O((3*n)*n)$$
> *1. $$O(n)$$ for copying all the elements in list.*
> *2. $$O(3*n)$$. one O(n) for `isSorted()` funciton, one O(n) for finding minSum index and one O(n) for removing elements in the list.*
> *3. in worst case senario we will executed all three function (isSorted, findMin index, remove element in list) n-1 times.* 

> *here $$O((3*n)*n)$$ is not exact as for every subsequent loop size of list is decreasing.* 
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: $$O(n)$$ for creating list.
> *we can perform all the operation on original list, but it is not encourage in interview process to mutate/chance the input data structure.* 
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {
    public boolean isSorted(List<Integer> list){
        for(int i = 1; i< list.size(); i++){
            if(list.get(i)<list.get(i-1))
                return false;
        }
        return true;
    }

    public int minimumPairRemoval(int[] nums) {
        
        List<Integer> temp = new ArrayList<>();
        for(int ele: nums)
            temp.add(ele);
        int count = 0;

        while(temp.size() > 1 && !isSorted(temp)){
            int minSum = Integer.MAX_VALUE;
            int index1 = -1;
            int index2 = -1;
            for(int i = 0; i < temp.size()-1; i++){
                int tempSum = temp.get(i)+temp.get(i+1);
                if(tempSum < minSum){
                    minSum  = tempSum;
                    index1  = i;
                    index2 = i+1;
                }
            }
            temp.set(index2,minSum);
            temp.remove(index1);
            count++;
        }
        return count;
    }
}
```
> ***if helpful please upvote. 😊 comment if you have any suggestions.***
['Array', 'Java']