Easy to understand CPP Solution || Using map and sorting
Intuition\nsort the nums array and store all the values of nums in the map\nthen calculate each posible value of k wrt nums[0].\n\n# Approach\n1 ->  sort the nu
# Intuition\nsort the nums array and store all the values of nums in the map\nthen calculate each posible value of k wrt nums[0].\n\n# Approach\n1 ->  sort the nums array\n2 -> store all the values of nums in the map\n3 -> calculate all posible values of k\n4 -> check for all values of K that the solution exists or not.\n\n\n# Code\n```\nclass Solution {\npublic:\n    \n    bool solve(int k, unordered_map<int, int> mp, vector<int> & nums, vector<int> &ans) {\n        int n = nums.size();\n        int i = 0;\n        \n        for(int i=0; i<n; i++){\n            if(mp[nums[i]] > 0) {\n                mp[nums[i]]--;\n                int next = nums[i] + 2*k;\n                if(mp[next] > 0) {\n                    mp[next]--;\n                    ans.push_back(nums[i] + k);\n                }\n                else\n                    return false;\n            }\n        }\n        return true;\n    }\n    \n    vector<int> recoverArray(vector<int>& nums) {\n        int n = nums.size();\n        sort(nums.begin(), nums.end());\n        vector<int> AllValuesOfK;\n        unordered_map<int, int> mp;\n        \n        // storing all values in map...\n        for(auto it : nums) {\n            mp[it]++;\n        }\n        \n        //   calculating all posible values of K...\n        for(int i=1; i<n; i++) {\n            int diff = nums[i] - nums[0];  //   checking for all values of k wrt nums[0].\n            if(diff > 0 && diff % 2 == 0)\n                AllValuesOfK.push_back(diff/2);   //  divided by 2 because the values are either (nums[i]+k) or (nums[i]-k)..\n        }\n        \n        int sz = AllValuesOfK.size();\n        //   check for all values of K..\n        for(int i=0; i<sz; i++) {\n            vector<int> ans;\n            if(solve(AllValuesOfK[i], mp, nums, ans))\n                return ans;\n        }\n        return {};\n    }\n};\n```
['Hash Table', 'Greedy', 'Sorting', 'C++']