[C++] try out the candidates of K.
\n\n\n// 2122. Recover the Original Array\nclass Solution {\n    static inline bool isEven(int n) {\n        return (n & 1) == 0;\n    }\n\n    static tuple<boo
\n\n```\n// 2122. Recover the Original Array\nclass Solution {\n    static inline bool isEven(int n) {\n        return (n & 1) == 0;\n    }\n\n    static tuple<bool, vector<int>> isGoodK(const int k, const vector<int>& A) {\n        unordered_multiset nset(A.begin(), A.end());\n        vector<int> originals;\n        originals.reserve(A.size() / 2);\n        // time complexity: O(n).\n        // space is also O(n).\n        for (int i = 0; i < A.size() && nset.size() > 0; ++i) {\n            const int upper = A[i] + 2 * k;\n            if (auto iter1 = nset.find(A[i]), iter2 = nset.find(upper);\n                iter1 != nset.end() && iter2 != nset.end()) {\n                // successfully paired up A[i] with another number.\n                originals.emplace_back(A[i] + k);\n                nset.erase(iter1);\n                nset.erase(iter2);\n            } else if (iter1 != nset.end()) {\n                // A[i] is available for pairing, but cannot find another number to pair it up.\n                // so, return earlier to indicate the failure.\n                return {false, {}};\n            }\n        }\n        return {true, originals};\n    }\n\npublic:\n    vector<int> recoverArray(vector<int>& nums) {\n        if (!isEven(nums.size())) {\n            return {}; // no valid answer.\n        }\n\n        sort(nums.begin(), nums.end());\n        const int smallest = nums.front();\n        // possible values for k\n        for (size_t i = 1; i < nums.size(); ++i) {\n            int diff = nums[i] - smallest;\n            if (isEven(diff) && diff >= 2) { // it should be 2*k, which is an even number\n                // this step is O(n)\n                auto [isGood, originalVec] = isGoodK(diff / 2, nums);\n                if (isGood) {\n                    return originalVec;\n                }\n            }\n        }\n        // Overall it\'s O(n ** 2).\n        return {}; // no valid answer\n    }\n};\n\n\n```
['C']