Java : check all possible Ks
nums contains permutation of {a-k,a+k, b-k,b+k,...,z-k,z+k}\n- we can sort permutation array and find all possible K : (nums[i]-nums[0])/2, for i>=1 and even (n
- **nums** contains permutation of **{a-k,a+k, b-k,b+k,...,z-k,z+k}**\n- we can sort permutation array and find all possible **K** : **(nums[i]-nums[0])/2**, for **i>=1** and **even (nums[i]-nums[0])**\n- we can map all occurrences of values into **value:count**\n- we have to iterate though all possible **K**s and check whether every **K** fits **nums** array\n- we can check by removing faced **nums** {**value**} and {**value +2 * k**} from map, if there is no corresponding {**value +2 * k**}, then **K** doesn\'t fit nums array\n```\n    public int[] recoverArray(int[] nums) {\n        int len = nums.length;\n        int[] res = new int[len/2];\n        Map<Integer,Integer> map = new HashMap<>();\n        Set<Integer> setK = new HashSet<>();\n\n        for(int n : nums)\n            map.put(n, map.getOrDefault(n,0)+1);\n\n        Arrays.sort(nums);\n\n        for(int i=1;i<len;i++){\n            int diff2k = nums[i]-nums[0];\n            if(diff2k%2==0 && diff2k!=0)\n                setK.add(diff2k/2);\n        }\n\n        for(int k : setK){\n            int i=0,j=0;\n            while(j<len/2){\n                int low = nums[i];\n                if(map.get(low)!=0) {\n                    int high = low + 2 * k;\n                    if(map.getOrDefault(high,0)!=0){\n                        map.put(low, map.get(low)-1);\n                        map.put(high, map.get(high)-1);\n                        res[j++] = low+k;\n                    }else{\n                        while(--j >= 0){\n                            map.put(res[j]+k, map.getOrDefault(res[j]+k, 0)+1);\n                            map.put(res[j]-k, map.getOrDefault(res[j]-k,0)+1);\n                        }\n                        break;\n                    }\n                }\n                i++;\n            }\n            if(j==len/2)\n                return res;\n        }\n        return null;\n    }\n```
[]