interesting tiny Python solution
IntuitionIs it easy to merge two arrays to create the maximum number possible without the limit K? And what is the problem with the limit K?ApproachThe problem
# Intuition
Is it easy to merge two arrays to create the maximum number possible without the limit K? And what is the problem with the limit K?

# Approach
The problem is that we can basically skip digits if we don't like them, which means shifting the pointer during merging
`merge` function.
![tempImageSYmj4r.jpg](https://assets.leetcode.com/users/images/201987dc-a3f8-48ac-be38-b1de06f1a933_1741698794.1377873.jpeg)
But how do we detect which numbers we need to skip and which ones to include? Easy — iterate from right to left and get the maximum number for the first place.
But are all numbers valid? No, a number is acceptable only if we have enough space for other digits.
Also, try to choose the leftmost number to have more choices
`largestk` function.

![tempImage2WfvMY.jpg](https://assets.leetcode.com/users/images/800e3e1e-47e7-4613-b6cd-8eaff860c90e_1741700066.7746654.jpeg)

And how many elements do we need to choose from each array? all possible ranges.

for example, 5:

0,5
1,4
2,3
3,2
4,1
5,0


<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
O(k*(n + m))

- Space complexity:
O(k*(n + m))

# Code
```python3 []
class Solution:
    def maxNumber(self, nums1: List[int], nums2: List[int], k: int) -> List[int]:
        # merge array
        def merge(nums1, nums2):
            n1, n2 = 0, 0
            merge = []
            while n1 < len(nums1) and n2 < len(nums2):
                if nums1[n1:] > nums2[n2:]:
                    merge.append(nums1[n1])
                    n1 += 1
                else:
                    merge.append(nums2[n2])
                    n2 += 1
            if n1 < len(nums1):
                merge.extend(nums1[n1:])
            else:
                merge.extend(nums2[n2:])
            return merge
        def largestk(nums, k):
            # numbers left = len(nums) - i
            l = -1
            res = []
            for _ in range(k):
                maxx = float("-inf")
                for r in range(len(nums) - 1, l, -1):
                    # check if the number is possible
                    if len(nums) - r >= k:
                        if maxx <= nums[r]:
                            maxx = nums[r]
                            l = r
                k -= 1
                res.append(maxx)
            return res
        res = []
        for i in range(k + 1):
            if i <= len(nums1) and k - i <= len(nums2):
                largest1 = largestk(nums1, i)
                largest2 = largestk(nums2, k - i)
                res = max(res, merge(largest1, largest2))
        return res



                        



```
['Array', 'Two Pointers', 'Greedy', 'Python', 'Python3']