<p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> of lengths <code>m</code> and <code>n</code> respectively. <code>nums1</code> and <code>nums2</code> represent the digits of two numbers. You are also given an integer <code>k</code>.</p>

<p>Create the maximum number of length <code>k &lt;= m + n</code> from digits of the two numbers. The relative order of the digits from the same array must be preserved.</p>

<p>Return an array of the <code>k</code> digits representing the answer.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums1 = [3,4,6,5], nums2 = [9,1,2,5,8,3], k = 5
<strong>Output:</strong> [9,8,6,5,3]
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums1 = [6,7], nums2 = [6,0,4], k = 5
<strong>Output:</strong> [6,7,6,0,4]
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> nums1 = [3,9], nums2 = [8,9], k = 3
<strong>Output:</strong> [9,8,9]
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>m == nums1.length</code></li>
	<li><code>n == nums2.length</code></li>
	<li><code>1 &lt;= m, n &lt;= 500</code></li>
	<li><code>0 &lt;= nums1[i], nums2[i] &lt;= 9</code></li>
	<li><code>1 &lt;= k &lt;= m + n</code></li>
</ul>

class Solution:
    def maxNumber(self, nums1: List[int], nums2: List[int], k: int) -> List[int]:
        """
        6 5
        9 8 3

        9 8 6 5 3

        3 4 6 5
        9 1 2 5 8 3

        1 9 3 2 8 5

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

        4 5 3 2 1 6 0 8
        length = 5

        l = [5 3 6 0 8]
        maxpop = 0
        i = 5

        
        i = 0
        0: 4 5 3 2 1 6 0 8
        1: 5 3 2 1 6 0 8
        2: 5 3 2 6 0 8
        3: 5 3 6 0 8
        4: 5 6 0 8
        5: 6 0 8
        6: 6 8
        7: 8
        8: 


        0: 3 4 6 5
        1: 4 6 5
        2: 6 5
        3: 6
        4:
        """
        def getMaxAfterRemovals(nums):
            n = len(nums)
            maxAfterRemovals = [copy.deepcopy(nums)]
            i = 0
            while i < len(maxAfterRemovals[-1]) - 1:
                if maxAfterRemovals[-1][i] < maxAfterRemovals[-1][i+1]:
                    maxAfterRemovals.append(maxAfterRemovals[-1][:i] + maxAfterRemovals[-1][i+1:])
                    i = max(0, i-1)
                else:
                    i += 1
            while len(maxAfterRemovals) < len(nums)+1:
                maxAfterRemovals.append(maxAfterRemovals[-1][:-1])
            return maxAfterRemovals

        maxAfterRemovals1 = getMaxAfterRemovals(nums1)
        maxAfterRemovals2 = getMaxAfterRemovals(nums2)

        def merge(nums1, nums2):
            i1 = i2 = 0
            n1 = len(nums1)
            n2 = len(nums2)
            merged = []
            while i1 < n1 and i2 < n2:
                if nums1[i1:] > nums2[i2:]:
                    merged.append(nums1[i1])
                    i1 += 1
                else:
                    merged.append(nums2[i2])
                    i2 += 1
            while i1 < n1:
                merged.append(nums1[i1])
                i1 += 1
            while i2 < n2:
                merged.append(nums2[i2])
                i2 += 1
            return merged

        def isGreater(nums1, nums2):
            i = 0
            while i < len(nums1):
                if nums1[i] > nums2[i]:
                    return True
                elif nums1[i] < nums2[i]:
                    return False
                i += 1
            return False
        
        result = None
        n1 = len(nums1)
        n2 = len(nums2)
        for count1 in range(k+1):
            if count1 <= n1 and (k-count1) <= n2:
                max1 = maxAfterRemovals1[n1-count1]
                max2 = maxAfterRemovals2[n2-k+count1]
                print(max1)
                print(max2)
                mergedNumber = merge(
                    max1, 
                    max2
                )
                if not result or isGreater(mergedNumber, result):
                    result = mergedNumber
        
        return result

19000