🔥💥⚡Easiest C++✅Python3✅Java✅C✅Python🐍✅☠💀 Beats 💯 Contest 28/04/2024🌛💥🔥
Intuition\n\n\n\nC++ []\nclass Solution {\npublic:\n    int minimumAddedInteger(vector<int>& nums1, vector<int>& nums2) {\n        sort(nums1.begin(), nums1.end
# Intuition\n![0ehh83fsnh811.jpg](https://assets.leetcode.com/users/images/26c0c08d-7471-4ca9-b95e-5c3a0f3e22c0_1714279850.06661.jpeg)\n![Screenshot 2024-04-28 101422.png](https://assets.leetcode.com/users/images/0d5edd69-60c8-4fbf-99fe-99419e436803_1714279857.6449218.png)\n![Screenshot 2024-04-28 101607.png](https://assets.leetcode.com/users/images/0be08290-1f43-431d-bed7-9e4e02883222_1714279862.1322696.png)\n```C++ []\nclass Solution {\npublic:\n    int minimumAddedInteger(vector<int>& nums1, vector<int>& nums2) {\n        sort(nums1.begin(), nums1.end());\n        sort(nums2.begin(), nums2.end());\n        int a = nums1[0], b = nums1[1], c = nums1[2], d = nums2[0];\n        if (f(nums1, 2, nums2, d - c))\n            return d - c;\n        if (f(nums1, 1, nums2, d - b))\n            return d - b;\n        return d - a;\n    }\n\nprivate:\n    bool f(vector<int>& nums1, int i, vector<int>& nums2, int x) {\n        int skip = i;\n        for (int k = 0; k < nums2.size();) {\n            if (nums1[i] + x != nums2[k]) {\n                if (skip++ < 2)\n                    i++;\n                else\n                    return false;\n            } else {\n                i++;\n                k++;\n            }\n        }\n        return true;\n    }\n};\n```\n```python3 []\nclass Solution:\n    def minimumAddedInteger(self, nums1: List[int], nums2: List[int]) -> int:\n        def solve():\n            d = nums2[0] - arr[0]\n            for i in range(1, n - 2):\n                if nums2[i] - arr[i] != d:\n                    return inf\n            return d\n\n        inf = 10**9\n        n = len(nums1)\n        nums2.sort()\n        ans = inf\n        for i in range(n):\n            for j in range(i):\n                arr = [nums1[k] for k in range(n) if k != i and k != j]\n                arr.sort()\n                ans = min(ans, solve())\n        return ans\n```\n```Java []\nclass Solution {\n    public int minimumAddedInteger(int[] nums1, int[] nums2) {\n        int[] ct1 = new int[3001];\n        int[] ct2 = new int[3001];\n        for (int x : nums1)\n            ct1[x + 1000]++;\n        for (int x : nums2)\n            ct2[x + 1000]++;\n        for (int i = -1000; i <= 1000; ++i) {\n            int diff = 0;\n            for (int j = 1000; j <= 2000; ++j) {\n                if (ct1[j] < ct2[i + j])\n                    diff += 10;\n                diff += ct1[j] - ct2[i + j];\n            }\n            if (diff <= 2)\n                return i;\n        }\n        return 1000000;\n    }\n}\n```\n```Python []\nclass Solution(object):\n    def minimumAddedInteger(self, nums1, nums2):\n        """\n        :type nums1: List[int]\n        :type nums2: List[int]\n        :rtype: int\n        """\n        nums1.sort()\n        nums2.sort()\n        ans = float(\'inf\')\n        n = len(nums1)\n        for i in range(n):\n            for j in range(i + 1, n):\n                l = nums1[:i] + nums1[i + 1:j] + nums1[j + 1:]\n                diff = nums2[0] - l[0]\n                if all(x - y == diff for x, y in zip(nums2, l)):\n                    # print(diff, nums2, l)\n                    ans = min(ans, diff)\n        return ans\n```\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n     O(n * m)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n     O(n)\n# Code\n```\nclass Solution(object):\n    def minimumAddedInteger(self, nums1, nums2):\n        """\n        :type nums1: List[int]\n        :type nums2: List[int]\n        :rtype: int\n        """\n        nums1.sort()\n        nums2.sort()\n        ans = float(\'inf\')\n        n = len(nums1)\n        for i in range(n):\n            for j in range(i + 1, n):\n                l = nums1[:i] + nums1[i + 1:j] + nums1[j + 1:]\n                diff = nums2[0] - l[0]\n                if all(x - y == diff for x, y in zip(nums2, l)):\n                    # print(diff, nums2, l)\n                    ans = min(ans, diff)\n        return ans\n```\n# Please upvote if it\'s useful\n![th.jpeg](https://assets.leetcode.com/users/images/dfa430fe-9fea-4b2b-9b5c-d7ea0110f3a9_1714279963.2317069.jpeg)\n
['Dynamic Programming', 'Bit Manipulation', 'C', 'Sorting', 'Python', 'C++', 'Java', 'Python3']