O(n * log(n)) time, O(1) space.
Complexity\n- Time complexity:\nO(n * log(n)), where n is the length of nums2 array.\n\n- Space complexity:\nO(1).\n\n# Code\njavascript []\n/**\n * @param {num
# Complexity\n- Time complexity:\nO(**n** * **log(n)**), where **n** is the length of *nums2* array.\n\n- Space complexity:\nO(**1**).\n\n# Code\n```javascript []\n/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number}\n */\nvar minimumAddedInteger = function (nums1, nums2) {\n    nums1.sort((a, b) => a - b);\n    nums2.sort((a, b) => a - b);\n\n    const n2 = nums2.length;\n    let x = 1001; // Larger than constarint\n    let diff, shift;\n\n    for (let i = 0; i < 3; i++) { // In case, first i elements in nums1 are duds.\n        diff = nums2[0] - nums1[i]; // First difference.\n        shift = i;\n        for (let j = 1; j < n2; j++) {\n            if (shift > 2) break; // If shift becomes 3, stop.\n            while (nums2[j] !== nums1[j + shift] + diff && shift < 4) { // If diff is wrong, increase shift; if shift becomes 3, stop.\n                shift++\n            }\n        }\n        if (shift < 3) {\n            x = Math.min(x, diff);\n        };\n    };\n\n    return x;\n};\n```
['Array', 'Sorting', 'JavaScript']