Sorting || Two Pointer
\n# Complexity\n- Time complexity:\n Add your time complexity here, e.g. O(n) \nO(n*m)\n-----\n- Space complexity:\n Add your space complexity here, e.g. O(n) \
\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n*m)\n-----\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\n-----\n```cpp []\nclass Solution {\npublic:\n    int minimumAddedInteger(vector<int>& nums1, vector<int>& nums2) {\n        int ans = INT_MAX;\n        sort(nums1.begin(), nums1.end());\n        sort(nums2.begin(), nums2.end());\n        int i=0;\n        while(i<nums1.size()){\n            int j=0, k=i;\n            int temp = nums2[j] - nums1[k];\n            k++,j++;\n            while(j<nums2.size() && k <nums1.size()){\n                if(nums2[j] - nums1[k] == temp) j++;\n                k++;\n            }\n            if(j == nums2.size()){\n                 ans = min(ans,temp);\n            }\n            i++;\n        }\n        return ans;\n    }\n};\n```\n```java []\nclass Solution {\n    public int minimumAddedInteger(int[] nums1, int[] nums2) {\n        int ans = 10000;\n        Arrays.sort(nums1);\n        Arrays.sort(nums2);\n        int i=0;\n        while(i<nums1.length){\n            int j=0, k=i;\n            int temp = nums2[j] - nums1[k];\n            k++;j++;\n            while(j<nums2.length && k <nums1.length){\n                if(nums2[j] - nums1[k] == temp) j++;\n                k++;\n            }\n            if(j == nums2.length){\n                 ans = Math.min(ans,temp);\n            }\n            i++;\n        }\n        return ans;\n    }\n}\n```\n\n
['Array', 'Two Pointers', 'Sorting', 'C++', 'Java']