Minimum pair removal
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
```python []
class Solution(object):
    def minimumPairRemoval(self, nums):
        operations = 0
        
        # Keep doing the operation until the array is non-decreasing
        while not self.isNonDecreasing(nums):
            min_sum = float('inf')
            min_index = -1
            
            # Find the leftmost pair with the minimum sum
            for i in range(len(nums) - 1):
                pair_sum = nums[i] + nums[i + 1]
                if pair_sum < min_sum:
                    min_sum = pair_sum
                    min_index = i
            
            # Replace the pair with their sum
            nums = nums[:min_index] + [nums[min_index] + nums[min_index + 1]] + nums[min_index + 2:]
            operations += 1

        return operations

    def isNonDecreasing(self, nums):
        for i in range(1, len(nums)):
            if nums[i] < nums[i - 1]:
                return False
        return True

# Example usage
sol = Solution()
print(sol.minimumPairRemoval([5, 2, 3, 1]))  # Output: 2
print(sol.minimumPairRemoval([1, 2, 2]))     # Output: 0

```
['Python']