3507. 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
```java []
import java.util.*;

class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {5, 2, 3, 1};
        System.out.println(solution.minimumPairRemoval(nums));
    }

    public int minimumPairRemoval(int[] nums) {
        int result = 0;
        List<Integer> newList = new ArrayList<>();
        for (int num : nums) { newList.add(num); }
        while (!checkArray(newList)) {
            int maxSum = Integer.MAX_VALUE;
            int minIndex = -1;
            for (int j = 0; j < newList.size() - 1; j++) {
                int sum = newList.get(j) + newList.get(j + 1);
                if (sum < maxSum) {
                    maxSum = sum;
                    minIndex = j;
                }
            }
            int sum = newList.get(minIndex) + newList.get(minIndex + 1);
            newList.set(minIndex, sum);
            newList.remove(minIndex + 1);
            result++;
        }
        return result;
    }

    public boolean checkArray(List<Integer> nums) {
        int count = 0;
        for (int i = 0; i < nums.size() - 1; i++) {
            if (nums.get(i) <= nums.get(i + 1)) {
                count++;
            } else {
                break;
            }
        }
        return count == nums.size() - 1;
    }

}



```
['Java']