(C++) 321. Create Maximum Number
\n\nclass Solution {\npublic:\n    vector<int> maxNumber(vector<int>& nums1, vector<int>& nums2, int k) {\n        vector<int> ans(k); \n        \n        auto 
\n```\nclass Solution {\npublic:\n    vector<int> maxNumber(vector<int>& nums1, vector<int>& nums2, int k) {\n        vector<int> ans(k); \n        \n        auto fn = [](vector<int>& arr, int k) {\n            vector<int> ans(k); \n            for (int i = 0, n = 0; i < arr.size(); ++i) {\n                while (n && ans[n-1] < arr[i] && n + arr.size() - i > k) --n; \n                if (n < k) ans[n++] = arr[i]; \n            }\n            return ans; \n        };\n        \n        auto cmp = [](vector<int>& val1, int i1, vector<int>& val2, int i2) {\n            for (; i1 < val1.size() && i2 < val2.size(); i1++, i2++) {\n                if (val1[i1] > val2[i2]) return true; \n                if (val1[i1] < val2[i2]) return false; \n            }\n            return i2 == val2.size(); \n        };\n        \n        for (int i = 0; i <= k; ++i) {\n            if (i <= nums1.size() && k-i <= nums2.size()) {\n                vector<int> val1 = fn(nums1, i), val2 = fn(nums2, k - i); \n                vector<int> cand; \n                for (int i1 = 0, i2 = 0; i1 < val1.size() || i2 < val2.size(); ) \n                    if (cmp(val1, i1, val2, i2)) cand.push_back(val1[i1++]);\n                    else cand.push_back(val2[i2++]); \n                ans = max(ans, cand); \n            }\n        }\n        return ans; \n    }\n};\n```
['C']