C++ solution, well explained.
Explanation:\n\nIdea 1: the first thing that popped into my head was to use recursion, the initial idea was to select an initial number and in each call stack h
**Explanation:**\n\nIdea 1: the first thing that popped into my head was to use recursion, the initial idea was to select an initial number and in each call stack have three different paths to take.\n1. \tchoose a number from array one\n2. \tchoose a number from array two\n3. \tdon\'t choose a number and move along \n\t\t\t* \tThe problem with this approach is that it is both time and memory expensive\n\t\t\nIdea 2: a greedy approach where i would take the lexigraphically greatest portion of array one merge it with the lexigraphically greatest portion of array two and collapse the arrays into themselves to be of size k, this idea works but we have to be careful.\n\nAlgorithm explained:\n\t1. \tpartition both arrays into a sub array of k, where each array contains the maximum lexigraphical order it can hold.\n\t\tThe subarrays are partitioned as such, (k - i) where i <= k would get you the first half and i gets the other half of that k sized array.\n*  \t\t    auto first = findMax(nums1, k - i);\n* \t\t      auto second = findMax(nums2, i);\n\t\n2. \tThen merge those two arrays ( k - i) and i into an array of size k , where the array of size K respects the rule of being in the greatest lexigraphical order it can hold.\n* \t\t while (nP < n && mP < m)\n        {\n              if(nums1[nP] == nums2[mP]){  \n                  int i = nP;  \n                  int j = mP;\n                  \n                  while( i < n && j < m && nums1[i] == nums2[j]){\n                      i++;\n                      j++;\n                  } \n                  \n                  if(i == n)\n                      res.push_back(nums2[mP++]);\n                  \n                  else if ( j == m)\n                      res.push_back(nums1[nP++]);\n                  \n                  else if(nums1[i] > nums2[j])\n                     res.push_back(nums1[nP++]); \n                  \n                  else\n                     res.push_back(nums2[mP++]); \n                    \n                continue; \n          } \n          if (nums1[nP] > nums2[mP])\n                res.push_back(nums1[nP++]);\n           else if(nums2[mP] > nums1[nP]) \n                res.push_back(nums2[mP++]);\n        }\n3. Lastly compare with our answer derived from previous iterations and update if needed.\n\t\t*`ans = compare(ans, tmp);`\n\n```\nclass Solution\n{\npublic:\n    void print(vector<int> & res){\n        for(int x : res)\n            cout << x << " ";\n        cout << endl;\n    }\n    \n    vector<int> findMax(vector<int> &nums, int k)\n    {\n        vector<int> res;\n        int n = nums.size();\n        for (int i = 0; i < n; i++)\n        {\n            int m = res.size();\n            while (m && res.back() < nums[i])\n            {\n                if (((n - i) + m - 1) >= k)\n                {\n                    res.pop_back();\n                    m--;\n                }\n                else\n                    break;\n            }\n            if (m < k)\n            {\n                m++;\n                res.push_back(nums[i]);\n            }\n        }\n        return res;\n    }\n\n    vector<int> compare(vector<int> &nums1, vector<int> &nums2)\n    {\n        int n = nums1.size();\n        int m = nums2.size();\n        if (n > m)\n            return nums1;\n        if (m > n)\n            return nums2;\n        for (int i = 0; i < n; i++)\n        {\n            if (nums1[i] > nums2[i])\n                return nums1;\n            else if (nums1[i] < nums2[i])\n                return nums2;\n        }\n        return nums1;\n    }\n    vector<int> merge(vector<int> &nums1, vector<int> &nums2)\n    {\n        vector<int> res;\n        int n = nums1.size();\n        int m = nums2.size();\n        int nP = 0;\n        int mP = 0;\n        while (nP < n && mP < m)\n        {\n              if(nums1[nP] == nums2[mP]){  \n                  int i = nP;  \n                  int j = mP;\n                  \n                  while( i < n && j < m && nums1[i] == nums2[j]){\n                      i++;\n                      j++;\n                  } \n                  \n                  if(i == n)\n                      res.push_back(nums2[mP++]);\n                  \n                  else if ( j == m)\n                      res.push_back(nums1[nP++]);\n                  \n                  else if(nums1[i] > nums2[j])\n                     res.push_back(nums1[nP++]); \n                  \n                  else\n                     res.push_back(nums2[mP++]); \n                    \n                continue; \n          } \n          if (nums1[nP] > nums2[mP])\n                res.push_back(nums1[nP++]);\n           else if(nums2[mP] > nums1[nP]) \n                res.push_back(nums2[mP++]);\n        }\n        while (nP < n)\n            res.push_back(nums1[nP++]);\n        while (mP < m)\n            res.push_back(nums2[mP++]);\n        return res;\n    }\n    \n    vector<int> maxNumber(vector<int> &nums1, vector<int> &nums2, int k)\n    {\n        vector<int> ans;\n        for (int i = 0; i < k; i++)\n        {\n            auto first = findMax(nums1, k - i);\n            auto second = findMax(nums2, i);\n            auto tmp = merge(first, second);\n            ans = compare(ans, tmp);\n        }\n        return ans;\n    }\n};\n```
['Greedy', 'C', 'C++']