Sorting || Beats 100% || C++
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nSort both the arrays an
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nSort both the arrays and check difference between elements of both arrays. If the difference is same for all elements, take the minimum of all the differences multiplied by (-1);\n\n# Complexity\n- Time complexity: O(N*N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\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\n        int mn = 1e9,i,j;\n\n        for(i=0;i+nums2.size()<=nums1.size();i++){\n\n            int d = nums1[i]-nums2[0],k=i,st=0;\n\n            for(j=0;j<nums2.size()&&k<nums1.size();j++){\n\n               if(nums1[k]-nums2[j]!=d){\n                  while(k<nums1.size()){\n                     if(nums1[k]-nums2[j]==d){st++;break;}\n                     k++;\n                  }\n                  k++;\n               }\n               else st++,k++;\n            }\n            if(st==nums2.size()) mn = min(mn,(-1)*d);\n        }\n\n        if(mn!=1e9) return mn;\n        else return 0;\n    }\n};\n```
['Sorting', 'C++']