Minimum Password Increments
Problem statement
You are given two integer arrays of equal length:
target, the required password.current, the current combination.
In one move, choose one index and increase current[i] by exactly 1. Return the minimum number of moves needed to make current equal to target.
If any target value cannot be reached because its current value is already larger, return -1.
Function
minimumPasswordIncrements(target: int[], current: int[]) → longExamples
Example 1
target = [4,6,3]current = [1,5,1]return = 6The required increases are 3, 1, and 2, for a total of 6 moves.
Example 2
target = [2,3]current = [2,3]return = 0The current combination already equals the password.
Example 3
target = [3,4]current = [5,1]return = -1The first current value is already greater than its target and values cannot be decreased.
Constraints
1 <= target.length == current.length <= 10^5.0 <= target[i], current[i] <= 10^9.- The answer fits in a signed 64-bit integer.