Easy solution bruteforce - 28/04/2024 contest
Intuition\nThis solution is pure bruteforce, we just create all combinaison of subarray possible and and check the condition for them\n\ndon\'t hesitate to upvo
# Intuition\nThis solution is pure bruteforce, we just create all combinaison of subarray possible and and check the condition for them\n\ndon\'t hesitate to upvote if you like the solution\n\n```python3 []\nclass Solution:\n    def minimumAddedInteger(self, nums1: List[int], nums2: List[int]) -> int:\n        n = len(nums2)\n        nums2.sort()\n        res = float(\'inf\')\n        for i in range(len(nums1)):\n            for j in range(i + 1, len(nums1)):\n                temp = nums1[:i] + nums1[i+1:j] + nums1[j+1:]\n                temp.sort()\n                curr = None\n                valid = True\n                for k in range(n):\n                    x = nums2[k] - temp[k]\n                    if curr is None:\n                        curr = x\n                    elif curr != x:\n                        valid = False\n                        break\n                if valid and (curr < res):\n                    res = curr\n        return res\n```\n```cpp []\nclass Solution {\npublic:\n    int minimumAddedInteger(vector<int>& nums1, vector<int>& nums2) {\n        int n = nums2.size();\n        std::sort(nums2.begin(), nums2.end());\n        int res = INT_MAX;\n        for (int i = 0; i < nums1.size(); i++) {\n            for (int j = i + 1; j < nums1.size(); j++) {\n                std::vector<int> temp;\n                for (int k = 0; k < nums1.size(); k++) {\n                    if (k != i && k != j) {\n                        temp.push_back(nums1[k]);\n                    }\n                }\n                std::sort(temp.begin(), temp.end());\n                int curr = 0;\n                bool valid = true;\n                for (int k = 0; k < n; k++) {\n                    int x = nums2[k] - temp[k];\n                    if (curr == 0) {\n                        curr = x;\n                    } else if (curr != x) {\n                        valid = false;\n                        break;\n                    }\n                }\n                if (valid && (curr < res)) {\n                    res = curr;\n                }\n            }\n        }\n        return res; \n    }\n};\n```\n```java []\nclass Solution {\n    public int minimumAddedInteger(int[] nums1, int[] nums2) {\n        int n = nums2.length;\n        Arrays.sort(nums2);\n        int res = Integer.MAX_VALUE;\n        for (int i = 0; i < nums1.length; i++) {\n            for (int j = i + 1; j < nums1.length; j++) {\n                int[] temp = new int[nums1.length - 2];\n                int index = 0;\n                for (int k = 0; k < nums1.length; k++) {\n                    if (k != i && k != j) {\n                        temp[index++] = nums1[k];\n                    }\n                }\n                Arrays.sort(temp);\n                Integer curr = null;\n                boolean valid = true;\n                for (int k = 0; k < n; k++) {\n                    int x = nums2[k] - temp[k];\n                    if (curr == null) {\n                        curr = x;\n                    } else if (curr != x) {\n                        valid = false;\n                        break;\n                    }\n                }\n                if (valid && (curr < res)) {\n                    res = curr;\n                }\n            }\n        }\n        return res; \n    }\n}\n```
['C++', 'Java', 'Python3']