Simple approach | Using map and all possible values of K | C++ Solution
Intuition\n Describe your first thoughts on how to solve this problesm. \nFinding all the possible values of K from the nums and then using map tp find out whet
# Intuition\n<!-- Describe your first thoughts on how to solve this problesm. -->\nFinding all the possible values of K from the nums and then using map tp find out whether given vlue of K is posiible or not.\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nStep 1: Sort nums.\nStep 2: Storing all possible values of K by finding (nums[i]-nums[0])/2;\nStep 3: Storing frequency of each element of nums in unordered map.\nStep 4: Using map to figure out whether given value of K is valid.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n   /* void solve(int ans)\n    {\n        ans = ans - 1;\n        cout<<ans<<"\\n";\n    }*/\n    \n    int solve(unordered_map<int , int> m , vector<int>& ans , int k  , vector<int>&nums)\n    {\n        \n        int i,j,l , p;\n        p = 0;\n        for(i=0;i<=nums.size()-1;i++)\n        {\n            if(m[nums[i]]>0)\n            {\n                cout<<"here"<<"\\n";\n                m[nums[i]]--;\n                l= nums[i] +2*k;\n                if(m[l]>0)\n                {\n                    m[l]--;\n                    \n                    ans.push_back(nums[i] + k);\n                }else{\n                    p  = -1;\n                    break;\n                }\n                \n                \n                \n                \n                \n            }\n        }\n        if(ans.size()>0)\n        { for(i=0;i<=ans.size()-1;i++)\n        {\n            cout<<ans[i]<<" ";\n        }}\n        if(p==-1)\n        {\n            return -1;\n        }\n        return 1;\n        \n        \n    }\n    vector<int> recoverArray(vector<int>& nums) {\n        int i,j,k,l;\n        vector<int> ans;\n        vector<int> v;\n       sort(nums.begin() , nums.end());\n        \n        for(i =1;i<=nums.size()-1;i++)\n        {\n            if((nums[i]-nums[0])%2==0)\n            {\n                k = (nums[i] - nums[0])/2;\n                if(k>0)\n                {v.push_back(k);}\n            }\n        }\n        \n        unordered_map<int, int> m;\n        for(i=0;i<=nums.size()-1;i++)\n        {\n            m[nums[i]]++;\n        }\n        l =-1;\n        for(i=0;i<=v.size()-1;i++)\n        {\n            vector<int> v1;\n            \n            if(solve(m ,v1 , v[i] ,nums)==1)\n            {\n                cout<<v[i]<<"\\n";\n                \n                return v1;\n                break;\n            }\n        }\n        return ans;\n        \n    }\n};\n```
['C++']