✅ Javascript | Simplest Solution | 🏆Sorting, Two pointers🏆 |🔥Beats 100%🔥
IntuitionExclude each 2 numbers in nums1 with double loop and check with two pointers minimal difference between each element of sorted nums1 and sorted nums2 a
![image.png](https://assets.leetcode.com/users/images/98defa82-dd54-47ce-8b91-efe5adb2911d_1741229932.1877184.png)

# Intuition
Exclude each 2 numbers in `nums1` with double loop and check with two pointers minimal difference between each element of sorted `nums1` and sorted `nums2` at the same order.

# Approach
Define:
`n` - length of `nums1`;
`minDiff` - minimal difference of elements;

Sorting both arrays at the same order.

With double loop exclude each 2 elements in `nums1`, then with two pointers `k` and `p` get difference of elements in `num1` and `num2` at the same positions.

On each iteration check current differnce `diff` with previous difference `prevDiff` and if they aren't same, break the loop, otherwise continue check.

After two pointers approach, update `minDiff` if `nums2` pointer equal length of `nums2`, it means that comparison was full from start to end without breaks.

Return `minDiff` at the end.

# Complexity
- Time complexity:
$$O(nums1^2)$$

- Space complexity:
$$O(1)$$

# Code
```javascript []
/**
 * @param {number[]} nums1
 * @param {number[]} nums2
 * @return {number}
 */
var minimumAddedInteger = function(nums1, nums2) {
    const n = nums1.length;
    let minDiff = Infinity;

    nums1.sort((a, b) => a - b);
    nums2.sort((a, b) => a - b);

    for (let i = 0; i < n; i++) {
        for (let j = i + 1; j < n; j++) {
            let p = 0, prevDiff = null;

            for (let k = 0; k < n; k++) {
                if (k === i || k === j) continue;

                const diff =  nums2[p] - nums1[k];

                if (prevDiff !== null && prev !== diff) break;

                prevDiff = diff;
                p++;
            }


            if (p === nums2.length) minDiff = Math.min(minDiff, prevDiff);
        }
    }

    return min;
};
```
['Two Pointers', 'Sorting', 'Enumeration', 'JavaScript']