#1187
Make Array Strictly Increasing
expert · 1225 · lc hard +32 · verified · 57.9% accepted · 2,347 likes · top 54%
Description
You are given two integer arrays arr1 and arr2. In each operation, pick any index i in arr1 and any index j in arr2, then set arr1[i] = arr2[j].
Find the minimum number of such operations to make arr1 strictly increasing. Return -1 if it is impossible.
Example 1:
Input: arr1 = [1,5,3,6,7], arr2 = [1,3,2,4]
Output: 1
Explanation: Replace 5 with 2, then arr1 = [1, 2, 3, 6, 7].
Example 2:
Input: arr1 = [1,5,3,6,7], arr2 = [4,3,1]
Output: 2
Explanation: Replace 5 with 3 and then replace 3 with 4. arr1 = [1, 3, 4, 6, 7].
Example 3:
Input: arr1 = [1,5,3,6,7], arr2 = [1,6,3,3]
Output: -1
Explanation: You can't make arr1 strictly increasing.
Code
1
2
3