Beats 100% of users || Easy explanation
\n# Explanation\nThe approach we follow is very simple.\nCalculate the difference(\'diff\') between the minimum elements of both the arrays and check if element
\n# Explanation\nThe approach we follow is very simple.\nCalculate the difference(\'diff\') between the minimum elements of both the arrays and check if elements at all indices have the same difference.\n\nBut when two array elements are deleted from the array nums1,\nthe least element of nums1 can be min1,min2 or min3\n\nwhere min1, min2 and min3 are first second and third minimum elements respectively before deletion.\n\nSo we have to repeat the process for three values of \'diff\' and return the minimum difference\n\nThe variable miss ensures that the arrays have atmost two misses(i.e., miss is when the difference is not equal to \'diff\')\n\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(N^2)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\n\n\n![image.png](https://assets.leetcode.com/users/images/320fd6c8-7f4f-4d85-a603-04449df28df4_1714286122.687863.png)\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        int min1=nums1[0],min2=nums1[1];\n\n        //first element is not removed from nums1\n        int diff=*min_element(nums2.begin(),nums2.end())-min1;\n        int miss=0;\n        int i=0,j=0;\n        while(miss<=2&&i<nums1.size()&&j<nums2.size())\n        {\n            if(nums2[j]-nums1[i]==diff)\n            {\n                i++;j++;\n            }\n            else\n            {\n                i++;miss++;\n            }\n        }\n        int res=INT_MAX;\n        if(miss<=2)\n        {\n            res=diff;\n        }\n\n        //first is removed and second is not removed\n        diff=*min_element(nums2.begin(),nums2.end())-min2;\n            miss=0;\n            i=0;j=0;\n            while(miss<=2&&i<nums1.size()&&j<nums2.size())\n            {\n                if(nums2[j]-nums1[i]==diff)\n                {\n                    i++;j++;\n                }\n                else\n                {\n                    i++;miss++;\n                }\n            }\n        if(miss<=2)\n            res=min(res,diff);\n\n        //both first and second are removed\n        diff=*min_element(nums2.begin(),nums2.end())-nums1[2];\n            miss=0;\n            i=0;j=0;\n            while(miss<=2&&i<nums1.size()&&j<nums2.size())\n            {\n                if(nums2[j]-nums1[i]==diff)\n                {\n                    i++;j++;\n                }\n                else\n                {\n                    i++;miss++;\n                }\n            }\n        if(miss<=2)\n            res=min(res,diff);\n        return res;\n    }\n};\n```\n\nPlease share your thoughts\nUpvote \uD83D\uDE4F\uD83D\uDE4F\uD83D\uDE4F
['C++']