Given two integer arrays arr1 and arr2, return the minimum number of operations to make arr1 strictly increasing. In one operation, you can replace any element in arr1 with any element from arr2. If impossible, return -1.
30:00
Java
Make Array Strictly Increasing
hard
Topics
Companies
Given two integer arrays arr1 and arr2, return the minimum number of operations to make arr1 strictly increasing. In one operation, you can replace any element in arr1 with any element from arr2. If impossible, return -1.
Example 1:
Input: {"arr1":[1,5,3,6,7],"arr2":[1,3,2,4]}
Output: 1
Constraints:
1≤arr1.length,arr2.length≤2000
0≤arr1[i],arr2[i]≤109
Input
arr ={"arr1":[1,5,3,6,7],"arr2":[1,3,2,4]}
arr1: [1, 5, 3, 6, 7], arr2: [1, 3, 2, 4]
arr1 (target array)
1
[0]
5
[1]
3
[2]
6
[3]
7
[4]
arr2 (replacement pool, sorted)
1
2
3
4
At each position: keep arr1[i] if valid, or replace with smallest valid from arr2