FastPrepMinimum Password Increments

Minimum Password Increments

Accenture logoAccenture● EasyINTERNOA
Learn

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[]) → long

Examples

Example 1

target = [4,6,3]current = [1,5,1]return = 6

The required increases are 3, 1, and 2, for a total of 6 moves.

Example 2

target = [2,3]current = [2,3]return = 0

The current combination already equals the password.

Example 3

target = [3,4]current = [5,1]return = -1

The 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.

More Accenture problems

See Accenture hiring insights
public long minimumPasswordIncrements(int[] target, int[] current) {
    // Write your code here.
}
target[4,6,3]
current[1,5,1]
expected6
Checking account…