Share my Python solution with explanation
To create the max number from num1 and nums2 with k elements, we assume the final result combined by i numbers (denotes as left) from num1 and j numbers (denote
To create the max number from num1 and nums2 with k elements, we assume the final result combined by i numbers (denotes as **left**) from num1 and j numbers (denotes as **right**) from nums2, where i+j==k.\n\nObviously, left and right must be the maximum possible number in num1 and num2 respectively. i.e. num1 = [6,5,7,1] and i == 2, then left must be [7,1]. \n\nThe final result is the maximum possible merge of all left and right. \n\nSo there're 3 steps:\n\n 1. **iterate i from 0 to k.**\n 2. **find max number from num1, num2 by select i , k-i numbers, denotes as left, right**\n 3. **find max merge of left, right**\n\nfunction **maxSingleNumber** select i elements from num1 that is maximum. The idea find the max number one by one. i.e. assume nums [6,5,7,1,4,2], selects = 3.\n1st digit: find max digit in [6,5,7,1], the last two digits [4, 2] can not be selected at this moment.\n2nd digits: find max digit in [1,4], since we have already selects 7, we should consider elements after it, also, we should leave one element out.\n3rd digits: only one left [2], we select it. and function output [7,4,2]\n\nfunction **mergeMax**  find the maximum combination of left, and right. \n\n\n    class Solution(object):\n    def maxNumber(self, nums1, nums2, k):\n        """\n        :type nums1: List[int]\n        :type nums2: List[int]\n        :type k: int\n        :rtype: List[int]\n        """\n        n, m= len(nums1),len(nums2)\n        ret = [0] * k\n        for i in range(0, k+1):\n            j = k - i\n            if i > n or j > m: continue\n            left = self.maxSingleNumber(nums1, i)\n            right = self.maxSingleNumber(nums2, j)\n            num = self.mergeMax(left, right)\n            ret = max(num, ret)\n        return ret\n\n\n    def mergeMax(self, nums1, nums2):\n        ans = []\n        while nums1 or nums2:\n            if nums1 > nums2:\n                ans += nums1[0],\n                nums1 = nums1[1:]\n            else:\n                ans += nums2[0],\n                nums2 = nums2[1:]\n        return ans\n\n    def maxSingleNumber(self, nums, selects):\n        n = len(nums)\n        ret = [-1]\n        if selects > n : return ret\n        while selects > 0:\n            start = ret[-1] + 1 #search start\n            end = n-selects + 1 #search end\n            ret.append( max(range(start, end), key = nums.__getitem__))\n            selects -= 1\n        ret = [nums[item] for item in ret[1:]]\n        return ret
[]