Minimum Password Increments
Updated
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.
More Accenture interview questions
- Nearest Composite NumberOA · Seen Sep 2026
- Reduce a Number to One DigitOA · Seen Sep 2026
- Candy DistributionOA · Seen Sep 2026
- Customers Who Never OrderedOA · Seen Sep 2026
- Economical TripOA · Seen Sep 2026
- Coin ChangeOA · Seen Sep 2026
- Validate Email AddressOA · Seen Sep 2026
- Closest Rhyming WordOA · Seen Aug 2026
- Array Leader ElementsOA · Seen Nov 2025
- Alternating Index Square SumONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Total Cost Against the Lowest Earlier PricePayPal · OAPayPal interview questions
- Count Valid Square PairsAuxoAI · OA
- Picked Player Who LostSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Server InvestmentRippling · OARippling interview questions
- Basic Item DiscountsPalantir · OAPalantir interview questions
- Next Pascal Row CoefficientIntuit · OAIntuit interview questions
- Unique Integers That Sum to ZeroNVIDIA · OANVIDIA interview questions
- Count Multiples of Three with Two SevensHudson River Trading · OAHudson River Trading interview questions
- Diagonal Bounce TraversalAutodesk · OAAutodesk interview questions
- Maximum Student-Teacher DistanceChubb · OAChubb interview questions