[Python3] greedy
\n\nclass Solution:\n    def maxNumber(self, nums1: List[int], nums2: List[int], k: int) -> List[int]:\n        \n        def fn(arr, k):\n            """Return
\n```\nclass Solution:\n    def maxNumber(self, nums1: List[int], nums2: List[int], k: int) -> List[int]:\n        \n        def fn(arr, k):\n            """Return largest sub-sequence of arr of size k."""\n            ans = []\n            for i, x in enumerate(arr): \n                while ans and ans[-1] < x and len(ans) + len(arr) - i > k: ans.pop()\n                if len(ans) < k: ans.append(x)\n            return ans\n            \n        ans = [0] * k\n        for i in range(k+1): \n            if k - len(nums2) <= i <= len(nums1): \n                val1 = fn(nums1, i)\n                val2 = fn(nums2, k-i)\n                cand = []\n                i1 = i2 = 0\n                while i1 < len(val1) or i2 < len(val2): \n                    if val1[i1:] >= val2[i2:]: \n                        cand.append(val1[i1])\n                        i1 += 1\n                    else: \n                        cand.append(val2[i2])\n                        i2 += 1\n                ans = max(ans, cand)\n        return ans \n```
['Python3']