Java HashMap O(n^2) with comments and explaination
\n\nThe idea is smallest element in the array would always be part of lower array so we can fix that element and iterate through rest of array to find possible 
\n\nThe idea is smallest element in the array would always be part of lower array so we can fix that element and iterate through rest of array to find possible k values, k would be equal to (nums[i]-nums[0])/2, now the next step is to verify if the taken k value is correct or not. For that we iterate over the array again and check if nums[j]+2*k or nums[j]-2*k element is present or not if none of this entries are present then k value we have taken is incorrect and we can move to new k value. If the element were present then we decrease frequency in hashmap so we can keep track if it was already checked or not.\n\n\n\n\n\n```\n\nclass Solution {\n    public int[] recoverArray(int[] nums) {\n        Arrays.sort(nums);\n        HashMap<Integer,Integer> hm=new HashMap<>();\n        for(int i=0;i<nums.length;i++){\n            hm.put(nums[i],hm.getOrDefault(nums[i],0)+1); //Stroing frequency of elements in hashmap\n        }\n        int ans[]=new int[nums.length/2];\n        for(int i=1;i<nums.length;i++){\n            int k=(nums[i]-nums[0])/2;  // Finding k values\n            if(k==0)\n                continue;    //K should be positive only\n            HashMap<Integer,Integer> hm2=new HashMap<>(hm); //Making copy of original hashmap\n            int index=0;\n            for(int j=0;j<nums.length;j++){\n                if(hm2.get(nums[j])>=1){\n\t\t\t\t\t//If element was not previously checked\n                    if(hm2.getOrDefault(nums[j]+2*k,0)>=1){\n                        ans[index]=nums[j]+k; //Original element is nums[j]+k\n                        hm2.put(nums[j],hm2.get(nums[j])-1);\n                        hm2.put(nums[j]+2*k,hm2.get(nums[j]+2*k)-1); // Decreasing frequency of both nums[j]&&nums[j]+k\n                    }\n                    else if(hm2.getOrDefault(nums[j]-2*k,0)>=1){\n                        ans[index]=nums[j]-k;   //Original element was nums[j]-k\n                        hm2.put(nums[j],hm2.get(nums[j])-1); \n                        hm2.put(nums[j]-2*k,hm2.get(nums[j]-2*k)-1); //Decreasing frequency of both nums[j]&&nums[j]+k\n                        \n                    }\n                    else{\n\t\t\t\t\t\t//Invalid k value \n                        break;\n                    }\n                    index++;\n                }\n            }\n            if(index==nums.length/2)\n                break; //Found the solution\n            \n        }\n        return ans;\n    }\n}\n\n```
['Java']