row and a pool of spare numbers spares. One replacement takes any element of row and overwrites it with any number from spares. Spares are never used up: the same one can be taken as often as you like.
The goal is to make row strictly increasing, with every number larger than the one before it. Return the minimum number of replacements (possibly 0). If it cannot be done, return -1.row=[2, 9, 4, 8], spares=[5, 3, 1] → 1
Replace 9 with the spare 3: [2, 3, 4, 8] is strictly increasing. One replacement is enough.
row=[6, 5, 4], spares=[7, 1, 8] → 2
Put 1 in place of 6 and 7 in place of 4 to get [1, 5, 7]. A single replacement is not enough.
row=[3, 3, 3], spares=[3] → -1
Every number in the row and among the spares is 3, so no strictly increasing row of three numbers can be built.
row) ≤ 2000spares) ≤ 2000row[i], spares[j] ≤ 10⁹row=[2, 9, 4, 8], spares=[5, 3, 1]
1
Run checks the first 3 tests in your browser. Submit checks all 147 tests on the server, hidden ones included.