Optimize Code Of Minimum Pair Removal To Sort Array-I....
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
```cpp []
class Solution {
public:
    bool isascend(vector<int>& nums) {
        for (int i = 0; i < nums.size()-1; i++) {
            if (nums[i] > nums[i + 1]) {
                return false;
            }
        }
        return true;
    }
    int minimumPairRemoval(vector<int>& nums) {
        int ans=0;
        while(!isascend(nums) && nums.size()>1){
            int pos=-1;
            int minsum=INT_MAX;
            for(int i=0;i<nums.size()-1;i++){
                int cursum=nums[i]+nums[i+1];
                if(cursum<minsum){
                    minsum=cursum;
                    pos=i;
                }
            }
            nums[pos]=nums[pos]+nums[pos+1];
            nums.erase(nums.begin()+pos+1);
            ans++;
        }
        return ans;
    }
};
```
['C++']