✅ Beats 100% Time & Space💯🔥|| Clean Code + Step-by-Step Approach 🚀
IntuitionEverytime we have to check if the array is sorted or not, if not sorted we have to get minimum Sum of adjacent pair and have to add that Minimum sum in
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Everytime we have to check if the array is sorted or not, if not sorted we have to get minimum Sum of adjacent pair and have to add that Minimum sum in place of that adjacent pair.

## **Things we have to Track**
- Starting index of adjacent pair (with minimum sum) to replace it with Minimum Sum.
- To Check if Array is sorted or not (for that we will use a helper Function)


# Approach
<!-- Describe your approach to solving the problem. -->
- I used a helper function to check is array is sorted or not
- if array is already sorted No need to do anything `return 0`;
- if Array is not sorted, then we will Check for minimum sum of adjacent pair and replace it with Minimum sum. 
- While loop run until our array becomes sorted in ascending order.
- Finally, `return count`.

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

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

# Code
```javascript []
/**
 * @param {number[]} nums
 * @return {number}
 */
var minimumPairRemoval = function (nums) {
    let count = 0;

    function isSortedIncreasing(nums) {
        for (let i = 0; i < nums.length - 1; i++) {
            if (nums[i] > nums[i + 1]) return false;
        }
        return true;
    }

    while (!isSortedIncreasing(nums)) {
        let minSum = Infinity;
        let index = -1;
        for (let i = 0; i < nums.length - 1; i++) {
            let sum = nums[i] + nums[i + 1];
            if (minSum > sum) {
                minSum = sum;
                index = i;
            }
        }
        nums.splice(index, 2, minSum);
        count++;
    }
    return count;
};
```
['JavaScript']