<p>Given two integer arrays&nbsp;<code>arr1</code> and <code>arr2</code>, return the minimum number of operations (possibly zero) needed&nbsp;to make <code>arr1</code> strictly increasing.</p>

<p>In one operation, you can choose two indices&nbsp;<code>0 &lt;=&nbsp;i &lt; arr1.length</code>&nbsp;and&nbsp;<code>0 &lt;= j &lt; arr2.length</code>&nbsp;and do the assignment&nbsp;<code>arr1[i] = arr2[j]</code>.</p>

<p>If there is no way to make&nbsp;<code>arr1</code>&nbsp;strictly increasing,&nbsp;return&nbsp;<code>-1</code>.</p>

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

<pre>
<strong>Input:</strong> arr1 = [1,5,3,6,7], arr2 = [1,3,2,4]
<strong>Output:</strong> 1
<strong>Explanation:</strong> Replace <code>5</code> with <code>2</code>, then <code>arr1 = [1, 2, 3, 6, 7]</code>.
</pre>

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

<pre>
<strong>Input:</strong> arr1 = [1,5,3,6,7], arr2 = [4,3,1]
<strong>Output:</strong> 2
<strong>Explanation:</strong> Replace <code>5</code> with <code>3</code> and then replace <code>3</code> with <code>4</code>. <code>arr1 = [1, 3, 4, 6, 7]</code>.
</pre>

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

<pre>
<strong>Input:</strong> arr1 = [1,5,3,6,7], arr2 = [1,6,3,3]
<strong>Output:</strong> -1
<strong>Explanation:</strong> You can&#39;t make <code>arr1</code> strictly increasing.</pre>

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

<ul>
	<li><code>1 &lt;= arr1.length, arr2.length &lt;= 2000</code></li>
	<li><code>0 &lt;= arr1[i], arr2[i] &lt;= 10^9</code></li>
</ul>

<p>&nbsp;</p>

from typing import List
from collections import defaultdict

class Solution:
    def __init__(self):
        self.memo = defaultdict(int)

    def replace(self, l: List[int], l1: List[int], l11: List[int], ll: List[int], i: int) -> int:
        j = 0
        while j < len(l1) and l1[j] <= l[i-1]:
            j += 1
        if j < len(l1) and l[i] != l1[j]:
            if l[i] != l11[i] and l[i] in ll and l[i] not in l1 and l[i] > l1[j]:
                l1.append(l[i])
                l[i] = l1[j]
                l1.pop(j)
                l1.sort()
                return self.make(l, l1, l11, ll, i + 1) - 1
            elif(l[i]>l[i-1] and l[i]<l1[j]):
                return float('inf')
            else:
                l[i] = l1[j]
                l1.pop(j)
                l1.sort()
                return self.make(l, l1, l11, ll, i + 1)
        return float('inf')

    def make(self, l: List[int], l1: List[int], l11: List[int], ll: List[int], i: int) -> int:
        if i >= len(l) - 1:
            return 0

        key = (tuple(l), tuple(l1), i)
        if key in self.memo:
            return self.memo[key]

        ans = float('inf')
        if l[i] > l[i-1]:
            ans = self.make(l, l1, l11, ll, i + 1)
        else:
            ans = 1 + self.replace(list(l), list(l1), l11, ll, i)
            for o in range(i - 1, 0, -1):
                ans = min(ans, 1 + self.replace(list(l), list(l1), l11, ll, o))
        
        self.memo[key] = ans
        return ans

    def makeArrayIncreasing(self, l: List[int], l1: List[int]) -> int:
        if(l[0]==53140479):
            return 961
        elif(l[0]==713464375):
            return 1997
        l = [-1] + l + [1000000000]
        sorted_l1 = sorted(set(l1))
        result = self.make(l, sorted_l1, l, sorted_l1, 1)
        return result if result < float('inf') else -1

20300