Skip to content

Commit

Permalink
Create 20-make-array-strictly-increasing.py
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Apr 20, 2023
1 parent 54bd5a4 commit 8f02319
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions 2023/04/20-make-array-strictly-increasing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from typing import List, Optional
from functools import cache
import sys, bisect

class Solution:
def makeArrayIncreasing(self, arr1: List[int], arr2: List[int]) -> int:
arr2.sort()
ma = float('inf')
@cache
def f(i,pre):
if i==len(arr1):return 0
res = ma
pos = bisect.bisect_right(arr2, pre)
if pos < len(arr2):
res = f(i+1, arr2[pos])+1
if arr1[i] > pre:
res = min(res, f(i+1, arr1[i]))
return res
ans = f(0,-1)
return ans if ans != ma else -1

0 comments on commit 8f02319

Please sign in to comment.