o(n^2) solution
\n\n# Code\n\nclass Solution {\n    public int minimumAddedInteger(int[] nums1, int[] nums2) {\n        HashMap<Integer,Integer> mp=new HashMap<>();\n        Ha
\n\n# Code\n```\nclass Solution {\n    public int minimumAddedInteger(int[] nums1, int[] nums2) {\n        HashMap<Integer,Integer> mp=new HashMap<>();\n        HashMap<Integer,Integer> mp1=new HashMap<>();\n        int n=nums1.length;\n        ArrayList<Integer> li=new ArrayList<>();\n        for(int i=0;i<n;i++){\n            mp1.put(nums1[i],mp1.getOrDefault(nums1[i],0)+1);\n        }\n        for(int i=0;i<n-2;i++){\n            for(int j=0;j<n;j++){\n                int diff=nums2[i]-nums1[j];\n                if(mp.getOrDefault(diff,0)==i){\n                    mp.put(diff,mp.getOrDefault(diff,0)+1);   \n                }\n                if(mp.getOrDefault(diff,0)==n-2){\n                    li.add(diff);\n                }\n            }\n        }\n       \n        Collections.sort(li);\n        //checking\n        for(int x:li){\n             HashMap<Integer,Integer> mp2=new HashMap<>(mp1);\n             int count=0;\n            for(int i=0;i<n-2;i++){\n                if(mp2.containsKey(nums2[i]-x)){ \n                    mp2.put(nums2[i]-x,mp2.get(nums2[i]-x)-1);\n                    if(mp2.get(nums2[i]-x)==0){\n                        mp2.remove(nums2[i]-x);\n                    }\n                    count++;\n                }\n                else{\n                    break;\n                }\n            }\n            if(count==n-2){\n                return x;\n            }\n        }\n        return li.get(0);\n    }\n}\n```
['Java']