Brute Force - Simple Solution - Easy to Understand - Python/Java/C++
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python3 []
def is_sorted(arr):
    return all(arr[i] <= arr[i+1] for i in range(len(arr) - 1))
    
class Solution:
    def minimumPairRemoval(self, nums: List[int]) -> int:
        ops = 0
    
        while len(nums) > 1 and not is_sorted(nums):
            arr = nums[:]
            min_sum = float('inf')
            min_ind = 0
            for i in range(len(arr) - 1):
                pair_sum = arr[i] + arr[i + 1]
                if pair_sum < min_sum:
                    min_sum = pair_sum
                    min_ind = i
            
            merged_val = arr[min_ind] + arr[min_ind + 1]
            new_arr = arr[:min_ind] + [merged_val] + arr[min_ind + 2:]
            nums = new_arr
            
            ops += 1
    
        return ops
```
```cpp []
class Solution {
private:
    bool isSorted(const vector<int>& arr) {
        for (size_t i = 0; i < arr.size() - 1; ++i) {
            if (arr[i] > arr[i + 1]) {
                return false;
            }
        }
        return true;
    }

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

        while (nums.size() > 1 && !isSorted(nums)) {
            vector<int> arr = nums;
            int minSum = INT_MAX;
            int minInd = -1;

            for (size_t i = 0; i < arr.size() - 1; ++i) {
                int pairSum = arr[i] + arr[i + 1];
                if (pairSum < minSum) {
                    minSum = pairSum;
                    minInd = i;
                }
            }

            int mergedVal = arr[minInd] + arr[minInd + 1];
            vector<int> newArr;
            for (int i = 0; i < minInd; ++i) {
                newArr.push_back(arr[i]);
            }
            newArr.push_back(mergedVal);
            for (size_t i = minInd + 2; i < arr.size(); ++i) {
                newArr.push_back(arr[i]);
            }
            nums = newArr;

            ops += 1;
        }

        return ops;
    }
};
```
```java []
class Solution {
    private boolean isSorted(List<Integer> arr) {
        for (int i = 0; i < arr.size() - 1; i++) {
            if (arr.get(i) > arr.get(i + 1)) {
                return false;
            }
        }
        return true;
    }

    public int minimumPairRemoval(int[] nums) {
        List<Integer> listNums = new ArrayList<>();
        for (int num : nums) {
            listNums.add(num);
        }

        int ops = 0;

        while (listNums.size() > 1 && !isSorted(listNums)) {
            List<Integer> arr = new ArrayList<>(listNums);
            int minSum = Integer.MAX_VALUE;
            int minInd = -1;

            for (int i = 0; i < arr.size() - 1; i++) {
                int pairSum = arr.get(i) + arr.get(i + 1);
                if (pairSum < minSum) {
                    minSum = pairSum;
                    minInd = i;
                }
            }

            if (minInd != -1) {
                int mergedVal = arr.get(minInd) + arr.get(minInd + 1);
                List<Integer> newArr = new ArrayList<>();
                for (int i = 0; i < minInd; i++) {
                    newArr.add(arr.get(i));
                }
                newArr.add(mergedVal);
                for (int i = minInd + 2; i < arr.size(); i++) {
                    newArr.add(arr.get(i));
                }
                listNums.clear();
                listNums.addAll(newArr);
                ops += 1;
            } else {
                break;
            }
        }

        return ops;
    }
}
```
['Array', 'C++', 'Java', 'Python3']