Sorting Frequency Comparision O(n) Time Complexity
\n# Complexity\n- Time complexity: O(nlogn)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n) 
\n# Complexity\n- Time complexity: $$O(nlogn)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int minimumAddedInteger(vector<int>& nums1, vector<int>& nums2) {\n        int n1 = nums1.size();\n        int n2 = nums2.size();\n        vector<int> count(1001,0);\n        sort(nums1.begin(),nums1.end());\n        sort(nums2.begin(),nums2.end());\n        for(int i=0;i<n1;i++) {\n            count[nums1[i]]++;\n        }\n        //frequency of 1st array\n        vector<int> original = count;\n        int mi = INT_MAX;\n        for(int i=0;i<3;i++) {\n            //iterate 3 times means we are comparing with minimum element of 2nd array with 1st 3 elements of 1st array\n            count = original;\n            int diff = nums1[i] - nums2[0];\n            //get the diff\n            count[nums2[0] + diff]--;\n            bool flag = true;\n            for(int j = 1;j < n2;j++) {\n                //add diff to every other element to in nums2 and check if that element is present in nums1 \n                if(count[nums2[j] + diff]) {\n                    count[nums2[j] + diff]--;\n                }\n                else {\n                    //if not break\n                    flag = false;\n                    break;\n                }\n            }\n            if(flag) {\n                //if every element is present then from all those possible differences get minimum\n                mi = min(mi,0 - diff);\n            }\n            //remove already processed element from original frequency\n            original[nums1[i]]--;\n        }\n        return mi;\n    }\n};\n```
['C++']