Easy to understand | 100% Beat | with Explanation
Intuition\n Describe your first thoughts on how to solve this problem. \nas we will remove 2 elments, we can just check for the diffrence between first 3 elemen
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nas we will remove 2 elments, we can just check for the diffrence between first 3 elements of nums1 with first el of nums 2, also validate if the diffrence is same for all the remaining elements.\n\n# Approach\nEasy to understand just look at the code\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$nlog(n)$$\n<!-- Add your time complexity here, e.g. $$O(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        int d = nums2[0] - nums1[2];\n        const int n = nums2.size();\n        bool ok = true;\n        for (int i = 1; ok && i < n; ++i) {\n            ok = nums2[i] - nums1[i + 2] == d;\n        }\n        if (ok) return d;\n        d = nums2[0] - nums1[1];\n        ok = true;\n        for (int i = 1, j = 2, c = 0; ok && i < n; ++i, ++j) {\n            if (nums2[i] - nums1[j] != d) {\n                if  (++c > 1) {\n                    ok = false;\n                } else {\n                    --i;\n                }\n            }\n            \n        }\n        if (ok) return d;\n        return nums2[0] - nums1[0];\n        \n        \n    }\n};\n```
['Greedy', 'C++']