Problem · Array
Focus on Efficiency (2024 NG)
Learn this problemProblem 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 problems
- Deduplicate Logs: Keep FirstONSITE INTERVIEW · Seen Jul 2026
- Deduplicate Logs: Keep LatestONSITE INTERVIEW · Seen Jul 2026
- Find a Template Across Binary-Tree LeavesONSITE INTERVIEW · Seen Jul 2026
- Maximum Programmer-Problem MatchingONSITE INTERVIEW · Seen Jul 2026
- Minimum Direction ViolationsONSITE INTERVIEW · Seen Jul 2026
- Stream Latest Log VersionsONSITE INTERVIEW · Seen Jul 2026
- Stream Unique Logs in Timestamp OrderONSITE INTERVIEW · Seen Jul 2026
- Top-K IP Addresses from File RecordsONSITE INTERVIEW · Seen Jul 2026