JS | Two approach | Beats 100% 🚀
Complexity
Time complexity: O(n³)

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

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

# Code
```javascript [-JS Approach 1 with in-place array update and while loop]
var minimumPairRemoval = function(n) {
    let c = 0;
    while (true) {
        let mn = Infinity, mi = 0, isSorted = true;
        for (let i = 0; i < n.length-1; i++) {
            if (n[i] > n[i+1]) isSorted = false;
            if (mn > n[i]+n[i+1]) {
                mn = n[i]+n[i+1]; mi = i
            }
        }
        if (isSorted) return c;
        n[mi] = mn; c++; n.splice(mi+1, 1);
    }
};
```

# Code
```javascript [-JS Approach 2 with recursion]
var minimumPairRemoval = function(n) {
    let mn = Infinity, mi = -1;
    for (let i = 0; i < n.length-1; i++) {
        if (mn > n[i]+n[i+1]) {
            mn = n[i]+n[i+1]; mi = i
        }
    }
    if (n.every((v,i) => !i || n[i-1] <= v) || mi === -1) return c;
    n[mi] = mn; c++;
    return minimumPairRemoval(n.slice(0, mi+1).concat(n.slice(mi+2)), c);
};
```
['JavaScript']