C++ || O(N^3)
Connect with me on LinkedIn: https://www.linkedin.com/in/abhay5349singh/\n\nApproach:\n sort arrays to have 1 to 1 mapping between possibly incremented or decre
**Connect with me on LinkedIn**: https://www.linkedin.com/in/abhay5349singh/\n\n**Approach:**\n* sort arrays to have 1 to 1 mapping between possibly incremented or decremented elements\n* since nums1 have 2 extra elements, we can `consider all pairs in nums1` and not include them while calculating difference between array elements\n* check if difference calculated in one go should be constant throughout and store min. difference\n\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 n=nums1.size();\n        int ans=INT_MAX;\n\t\t\n        for(int i=0;i<n-1;i++){\n            for(int j=i+1;j<n;j++){\n                int idx=0; // to iterate over nums2\n\t\t\t\t\n                bool diff_found = false;\n                int possible_diff = INT_MAX;\n                bool valid_diff = true;\n\t\t\t\t\n                for(int k=0;k<n;k++){\n                    if(k==i || k==j) continue; // skipping 2 indices from nums1\n                    \n                    if(diff_found == false){\n                        diff_found = true;\n                        possible_diff = nums2[idx]-nums1[k];\n                    }else{\n                        int diff = nums2[idx]-nums1[k];\n                        if(diff != possible_diff){\n                            valid_diff = false;\n                            break;\n                        }\n                    }\n                    \n                    idx++;\n                }\n                \n                if(valid_diff) ans = min(ans, possible_diff);\n            }\n        }\n        \n        return ans;\n    }\n};\n```\n\n**Do upvote if it helps :)**
[]