Easy to understand | All Possible K | TC - O(k*n) | k is all possible k values
cpp\nclass Solution {\npublic:\n    vector<int> recoverArray(vector<int>& nums) {\n        int n = nums.size(); \n        if(n==2) return {(nums[0]+nums[1])/2};
```cpp\nclass Solution {\npublic:\n    vector<int> recoverArray(vector<int>& nums) {\n        int n = nums.size(); \n        if(n==2) return {(nums[0]+nums[1])/2};\n        sort(nums.begin(), nums.end()); \n        \n        set<int> lower; \n        for(int i = 1; i < n; i++) {\n            if((nums[i]-nums[0])%2==0 and nums[i]!=nums[0]) lower.insert((nums[i]-nums[0])/2);\n        }\n                \n        unordered_map<int, int> temp; \n        for(int i = 0; i < n; i++) {\n            temp[nums[i]]++;\n        }\n        \n        unordered_map<int, int> check; \n        for(auto &it : lower) {\n            int low = it; \n            \n            vector<int> res; \n            int size = 4;\n            \n            check = temp; \n            \n            res.push_back(nums[0]+low);\n            check[nums[0]]--;\n            check[nums[0]+2*low]--; \n            \n            \n            res.push_back(nums[n-1]-low);\n            check[nums[n-1]]--;\n            \n            if(!check[nums[n-1]-2*low]) continue; \n            \n            check[nums[n-1]-2*low]--;\n\n            for(int i = 0; i < n; i++) {\n                \n                if(!check[nums[i]]) continue; \n                \n                if(check[nums[i]+2*low]) {\n                    res.push_back(nums[i]+low);\n                    check[nums[i]]--;\n                    check[nums[i]+2*low]--;\n                    size += 2;\n                }\n\n                else if(check[nums[i]-2*low]){\n                    res.push_back(nums[i]-low);\n                    check[nums[i]]--;\n                    check[nums[i]-2*low]--;\n                    size += 2;\n                }\n\n            }       \n            if(size == n) {\n                return res; \n            }\n        }\n        \n        return {}; \n    }\n};\n```
['C']