Simple solution for minimun added integer
IntuitionThe idea is to check diff between elements in nums1 and nums2. If the current nums1 add with diff not equal nums2, we increase the count. If we count m
# Intuition
The idea is to check diff between elements in nums1 and nums2. If the current nums1 add with diff not equal nums2, we increase the count. If we count more than 2 (it should be more than 2 because as the description there are 2 numbers will be removed in nums1). The solution is based on ***@Fahad06***, his solution is implemented in C++.

Fahad06's solution link: https://leetcode.com/problems/find-the-integer-added-to-array-ii/solutions/5082036/o-n-2-o-n-logn-c/

# Approach
**Step 1:** I sort nums1 and nums2 array by ASC.

**Step 2:** I loop through nums1 and calculate diff between nums2[0] and nums1[i].

**Step 3:** Check the diff is the same with all diff that we calculate between nums1's element and nums2's element.

**Step 4:** I create the function for checking diff between elements in nums1 and nums2.
- I create the count variable for counting the invalid pairs.
- If the current nums1[i] + diff not equal the nums2[j], we will increase the count.
- Else I move to next nums2 to compare diff with other numbers in nums1.
- After the loop, if the count is more than 2, we return that the diff is not true for all numbers in nums1 and nums2. Because 2 numbers can be removed in nums1 so there are 2 pairs that not equal with other diff still true.

**Step 5:** If I check diff with nums1 and nums2 correct, I will update the result with min of previous diff and the current diff.

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

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

# Code
```typescript []
function checkDiffElements(nums1: number[], nums2: number[], diff: number): boolean {
    let count = 0;
    let j = 0;

    for (let i = 0; i < nums1.length; i++) {
        if (nums1[i] + diff !== nums2[j]) count++
        else j++;
    }

    if (count > 2) return false;

    return true;
}

function minimumAddedInteger(nums1: number[], nums2: number[]): number {
    let result: number = Infinity;

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

    for (let i = 0; i < nums1.length; i++) {
        let d = nums2[0] - nums1[i];

        if (checkDiffElements(nums1, nums2, d)) result = Math.min(result, d);
    }

    return result;
};
```
['Two Pointers', 'Sorting', 'TypeScript']