✅ C++ | 94% Faster | Stack Solution | Merge Sort Variation
321. Create Maximum Number\n\nTime Complexity : O(n2)\nSpace Complexity : O(n)\n\n\nvector<int> maxNumber(vector<int>& nums1, vector<int>& nums2, int k) {\n    
[**321. Create Maximum Number**](https://leetcode.com/problems/create-maximum-number/)\n\n**`Time Complexity : O(n2)`**\n**`Space Complexity : O(n)`**\n\n```\nvector<int> maxNumber(vector<int>& nums1, vector<int>& nums2, int k) {\n        int m=nums1.size(), n=nums2.size();\n        vector<int>res(k);\n        for(int i=0; i<=k; i++){\n            if(i<=m and k-i<=n){\n                vector<int>v1=maxArray(nums1, i), v2=maxArray(nums2, k-i);\n                vector<int>v=merge(v1,v2 , k);\n                res=max(res, v);\n            }\n        }\n        return res;\n    }\n\t\n    vector<int>merge(vector<int>&nums1 , vector<int>&nums2, int k){\n        vector<int>v(k);\n        for(int i=0, j=0, t=0;t<k; t++){\n            v[t]=cmp(nums1,i, nums2, j)?nums1[i++]:nums2[j++];\n        }\n        return v;\n    }\n\t\n    bool cmp(vector<int>&nums1, int i, vector<int>&nums2,int j){\n        while(i<nums1.size() and j<nums2.size() and nums1[i]==nums2[j]){\n            i++, j++;\n        }\n        return j==nums2.size() or (i<nums1.size() and nums1[i]>nums2[j]);\n    }\n\t\n    vector<int>maxArray(vector<int>&nums, int k){\n        int n=nums.size();\n        vector<int>v;\n        for(int i=0; i<n; i++){\n            while(v.size()+n-i>k and !v.empty() and v.back()<nums[i])v.pop_back();\n            if(v.size()<k)v.push_back(nums[i]);\n        }\n        return v;\n    }\n```\n***Happy Coding :)***\n```\nif(liked(\u2764\uFE0F)==true) Upvote(\u2B06\uFE0F);\nelse Comment(\uD83D\uDCDD);\nreturn Thank You\uD83D\uDE01;\n```\n![image](https://assets.leetcode.com/users/images/77d4616f-979f-4fd2-acdf-6cf04532de46_1665998757.740748.png)\n
['Stack', 'C', 'Merge Sort']