Focus on Efficiency (2024 NG)
Updated
Problem statement
Given an array of integers A, with each move you can select an arbitrary range and increment all the numbers in that range by 1. Return the number of moves needed to transform an array starting with all zeros into A.
Function
minMoves(A: int[]) → intExamples
Example 1
A = [2, 1, 3]return = 4
To transform [0, 0, 0] into [2, 1, 3] requires 4 moves, as follows:
[0, 0, 0] -> [1, 1, 1] -> [2, 1, 1] -> [2, 1, 2] -> [2, 1, 3]
Constraints
1 <= A.length <= 10^50 <= A[i] <= 10^4
More Google interview questions
- Swap Adjacent in LR StringONSITE INTERVIEW · Seen Dec 2026
- Count Winning Dice Face PairsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Find a Failing Test PairONSITE INTERVIEW · Seen Nov 2026
- Logger Rate LimiterPHONE SCREEN · Seen Nov 2026
- Logger Rate Limiter with Every-Arrival HistoryPHONE SCREEN · Seen Nov 2026
- Minimum Cars for Rental RequestsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Minimum Operations to Make a SubsequenceOA · Seen Nov 2026
- Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Minimum AmountBelvedere Trading · OA
- Minimum Cost K-Capable ModelsMicrosoft · OAMicrosoft interview questions
- Optimal TransferSnowflake · OASnowflake interview questions
- Minimize Warehouse Transfer CostAmazon · OA
- Gas Station Loop StartNutanix · OANutanix interview questions
- Running Through Walls with Limited EnergyScale AI · OAScale AI interview questions
- Redistribute MegaseedsRubrik · OARubrik interview questions
- Make the Array PositiveAtlassian · OAAtlassian interview questions
- Maximum Distinct Items Within a BudgetAdobe · OAAdobe interview questions
- Maximize Compatible Car RidersUber Freight · PHONE SCREEN · ONSITE INTERVIEWUber Freight interview questions